Lua [ Hooks ]

hello guys , i’ve been trying to fix this for more than 1 hour , and i can’t find the error :confused:

( who can help me ? thanks ! )

ERROR:



ERROR: Hook 'AB.T' Failed: [xxxxx:182] attempt to perform arithmetic on field 'MaxArmor' (a nil value)
Removing Hook 'AB.T'
ERROR: Hook 'hB.T' Failed: [xxxxx:148] attempt to call method 'GetMaxHealth' (a nil value)
Removing Hook 'hB.T'


My Server Codification:




function DoHPThink()
        for k, v in pairs (player.GetAll()) do
                if v:IsPlayer() and v:IsValid() then
                        if v.WaitTime == nil then v.WaitTime = 4 end
                        if v.lastHit == nil then v.lastHit = CurTime() end
                        if v.lastHeal == nil then v.lastHeal = CurTime() end
                        if CurTime() - v.lastHit > v.WaitTime then
 LINE 148                    if v:Health() != math.floor ( math.ceil( v:Health() / v:GetMaxHealth() ) * v:GetMaxHealth() ) and CurTime() - v.lastHeal > 1 / v.RegTime then
                                        v:SetHealth( v:Health() + 1 )
                                        v.lastHeal = CurTime()
                                end
                        end
                        v.lastHealth = v:Health()
                end
        end
end
hook.Add ("Think", "hB.T", DoHPThink)



and the second error




function DoArmorThink()
		for k,v in pairs (player.GetAll()) do
			if v.WaitTimeA == nil then v.WaitTimeA = 4 end
			if v.lastHitA == nil then v.lastHitA = CurTime() end
			if v.lastHealA == nil then v.lastHealA = CurTime() end
			if CurTime() - v.lastHitA > v.WaitTimeA then
 LINE 182  	        	if v:Armor() <= v.MaxArmor - 1 and CurTime() - v.lastHealA > 1/v.RegArmTime then
					v:SetArmor (v:Armor() + 1)
					v.lastHealA = CurTime()
				end
			end
			v.lastArmor = v:Armor()
		end
	end
	hook.Add ("Think", "AB.T", DoArmorThink)



Thanks FacePunch Community

[lua]
function DoArmorThink()
for k,v in pairs (player.GetAll()) do
if v.WaitTimeA == nil then v.WaitTimeA = 4 end
if v.lastHitA == nil then v.lastHitA = CurTime() end
if v.lastHealA == nil then v.lastHealA = CurTime() end
if CurTime() - v.lastHitA > v.WaitTimeA then
if( v.MaxArmor ) then
LINE 182 if v:Armor() <= v.MaxArmor - 1 and CurTime() - v.lastHealA > 1/v.RegArmTime then
v:SetArmor (v:Armor() + 1)
v.lastHealA = CurTime()
end
end
v.lastArmor = v:Armor()
end
end
hook.Add (“Think”, “AB.T”, DoArmorThink)
[/lua]

for first error.

And for second error:
[lua]
function DoHPThink()
for k, v in pairs (player.GetAll()) do
if v:IsPlayer() and v:IsValid() then
if v.WaitTime == nil then v.WaitTime = 4 end
if v.lastHit == nil then v.lastHit = CurTime() end
if v.lastHeal == nil then v.lastHeal = CurTime() end
if CurTime() - v.lastHit > v.WaitTime then
if( v.GetMaxHealth ) then
LINE 148 if v:Health() != math.floor ( math.ceil( v:Health() / v:GetMaxHealth() ) * v:GetMaxHealth() ) and CurTime() - v.lastHeal > 1 / v.RegTime then
v:SetHealth( v:Health() + 1 )
v.lastHeal = CurTime()
end
end
v.lastHealth = v:Health()
end
end
end
hook.Add (“Think”, “hB.T”, DoHPThink)
[/lua]

if the functions stop working, then that means v.MaxArmor is nil, and so is v.GetMaxHealth().