I am trying to give an entity some health and lose some when shot at
function ENT:OnTakeDamage(dmg) self:TakePhysicsDamage(dmg); -- React physically when getting shot/blown if(self:Health <= 0) then return; end -- If the health-variable is already zero or below it - do nothing self:Health = self:Health - dmg:GetDamage(); -- Reduce the amount of damage took from our health-variable print(self:Health) if(self:Health <= 0) then -- If our health-variable is zero or below it self:Remove(); -- Remove our entity end end
It does not like the
part. Seems to think its nil.
Its currently set on Initialize
function ENT:Initialize() self:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics, self:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics self:SetSolid( SOLID_VPHYSICS ) -- Toolbox self:SetHealth(100) end
Whats going on? Why is health nil after being set?