# Give armor instead of set armor?

I was wondering how to do this with armor.

This didn’t work

``````

local plyArmor = ply:Armor()
ply:SetArmor(math.Clamp(plyArmor + 50, 0, ply:GetMaxArmor()))

``````

[lua]
local a = FindMetaTable( “Player” )
a:GetMaxArmor = function() return 200 end
[/lua]
[lua]
ply:SetArmor( math.Clamp( ply:Armor() + 50, 0, 200 ) )
[/lua]

When I use this code, the npc doesn’t spawn anymore.

Nobody knows? It´s not so hard is it?

Is GetMaxArmor defined?

I dont think so.

Define it yourself in that case. Either use a number, or a function like SIR TE5T made if you plan on reusing it

Basically choose a maximum

Well, the Sir´s code didn’t work, what code do I use then?

Replace the last argument of math.Clamp with a number that represents the maximum armor

``````

local PLAYER            = FindMetaTable( 'Player' ) -- Finds the players meta table
local max               = 200 -- Set this to the max armor you want the player to be able to have

function PLAYER:GiveArmor( amt ) -- This code can only be ran on players, as it is in the "Player" meta table
self:SetArmor( math.Clamp( self:Armor() + amt, 0, max ) ) -- Sets the armor to the players current armor + the amount you input, but doesn't allow it to go past the "max" variable you set in the beginning
end

``````

Then just use Player:GiveArmor( insertamount ) anywhere (be sure it’s server side -_-)

So this is the part of my code.

``````
net.Receive( "GiveArmorNPC50", function( len, ply )
local PLAYER            = FindMetaTable( 'Player' ) -- Finds the players meta table
local max               = 100 -- Set this to the max armor you want the player to be able to have

function PLAYER:GiveArmor( 50 ) -- This code can only be ran on players, as it is in the "Player" meta table
self:SetArmor( math.Clamp( self:GetArmor() + 50, 0, max ) ) -- Sets the armor to the players current armor + the amount you input, but doesn't allow it to go past the "max" variable you set in the beginning
end
if ply:Armor() < 100 then
if ply.DarkRPVars.money > 500 then
ply:PrintMessage(HUD_PRINTTALK, "Here you go! Thanks for purchasing armor.")
Player:GiveArmor(50)
else
ply:PrintMessage(HUD_PRINTTALK, "Sorry! You don't have enough money to buy armor.")
end
else
ply:PrintMessage(HUD_PRINTTALK, "You have full armor! I refuse to give you more.")
end

``````

What am I doing wrong?

Although this wont change much, but keep the code i gave you on it’s own (outside the net.receive function)

when are you sending the net message? and to be sure that it’s being received, add print( ‘received net message’ ) to the beginning of the function to make sure it’s being received by the server and check the server console.

Your problem is you do Player:GiveArmor, while the it should be ply:GiveArmor.