Need help using Self in hook Think

So I made a Think hook and I want it to check if the entity(self) is valid and if not then destroy a timer.
Here is the code:



function ENT:Initialize()
	self:SetModel("models/props_trainstation/trainstation_ornament001.mdl")
	self:PhysicsInit(SOLID_VPHYSICS)
	self:SetMoveType(MOVETYPE_VPHYSICS)
	self:SetSolid(SOLID_VPHYSICS)

	healthprogress = 0

	timer.Create('HealthTimerProgress',5,0,function()
		healthprogress = healthprogress + 1
	end)

	self:SetColor(Color(0, 180, 225))

	local phys = self:GetPhysicsObject()

	if(phys:IsValid()) then
		phys:Wake()
	end
end

function CheckIfValid()
	if self:IsValid() then
		print(healthprogress)
	else
		timer.Destroy('HealthTimerProgress')
	end
end

hook.Add('Think', 'TimerDestroyer', CheckIfValid)

Here is the error:



[ERROR] addons/zerosprinters/lua/entities/healthprinter/init.lua:28: attempt to index global 'self' (a nil value)
  1. fn - addons/zerosprinters/lua/entities/healthprinter/init.lua:28
   2. unknown - addons/ulib/lua/ulib/shared/hook.lua:110


That is very wrong. Entities can have think hooks of their own. Don’t use hook.Add for this.

ENT:Think

Shouldn’t be using a timer either.

self isn’t a global variable, so it’s not valid to use here. Just check if it’s valid inside the timer, if not remove it.

Also, healthprogress is going to be shared between all entities you spawn of this type, just in case that’s not what you wanted.

So I tried that with a function (function ENT:Think()) but I get the same error.
Here is my code:


function ENT:Think()
	if ENT:IsValid() then
		print(healthprogress)
	else
		timer.Destroy('HealthTimerProgress')
	end
end

[editline]11th February 2017[/editline]

@bigdogmat After reading what you said I feel like a total retard because I didn’t do that before, sorry for wasting your time.