Pointshop Health Regen Error


Lua Error: [ERROR] addons/pointshop/lua/pointshop/items/donator/healthregeneration.lua:7: Tried to use a NULL entity! 1. Health - [C]:-1 2. unknown - addons/pointshop/lua/pointshop/items/donator/healthregeneration.lua:7

healthregen.lua


ITEM.Name = 'Health Regeneration'
ITEM.Price = 1000
ITEM.Model = 'models/props_junk/GlassBottle01a.mdl'

function ITEM:OnEquip(ply, modifications)
	timer.Create("healthregen_"..ply:SteamID(), 1, 0, function()
		if ply:Health() < ply:GetMaxHealth() then
			ply:SetHealth(math.min(ply:Health() + 1, ply:GetMaxHealth()))
		end
	end)
end

function ITEM:OnHolster(ply)
	timer.Destroy("healthregen_"..ply:SteamID())
end

The error is probably cause somewhere else, where you do


function ITEM:OnEquip(ply, modifications)

have to you check make sure you acctually passing the function a player entity. What I mean is when you cann the function do you give it a valid entity?

But it’s not an entity.

A Player is an entity. So passing the player entity would be giving it an entity :stuck_out_tongue:

The player left when you did it probably
do an isvalid check inside the timer

[editline]12th January 2015[/editline]

I mean the player left before the timer expired, so the code was called, and since the player didn’t exist it errored