Lua Problem - Stare

I am developing 3 entities which are nearly done, yet I am running into an error.
I want it so if the player looks at the entity for 4 seconds, it plays an overlay and kills the player using a timer. (Done)
I also want it so if the player looks away, the timer is cancelled and no overlay is shown.
To stop the death timer, this is what I have done
[lua]function ENT:BeCreepy()
self.Victim:ConCommand( “pp_mat_overlay effects/combine_binocoverlay.vmt” ) --TESTING
timer.Destroy( “stare” )
timer.Destroy( “neardeath” )[/lua]
That should make it so that the timer to kill the player is gone,

But for the stare overlay, I have
[lua]function ENT:CanVictimSeeUs()
self.Victim:ConCommand( “pp_mat_overlay •” )–TESTING
timer.Create( “neardeath”, 3.5, 1, function()
–if !IsValid(self.Victim) then return end
self.Victim:ConCommand( “pp_mat_overlay overlays/test/test” )

timer.Create( “stare”, 4, 1, function()
if !IsValid(self.Entity) then return end
self.Victim:ConCommand( “pp_mat_overlay overlays/test/test” )
self.Victim:ConCommand( “kill” )
self:EmitSound(“test/scream.wav”, 500, 100)

timer.Create( "death2", 5, 1, function()
if !IsValid(self.Victim) then return end
self.Victim:ConCommand( "pp_mat_overlay •" )		

^^Makes it so you die after a few seconds of staring

I can get the death overlay timer to work just fine, staring for 4 seconds kills the player and displays an overlay, but the twist is, I want to make it so when you look away, the timers are destroyed leaving the player unharmed.
To do that, I would use timer.Destroy.
function ENT:Think()
if not IsValid( self.Victim ) or not self.Victim:Alive() then
if self:CanVictimSeeUs() then
self:NextThink( CurTime() + 6 )
self:NextThink( CurTime() + 2 )
return true
BeCreepy is when the entity is moving, so where that is, is the 2 lines to destroy the timer.
But when I place those 2 there, the npc kills the player, but looking away does nothing. I think this is because the destroy timer function is called too late, the curtime is involved. Can someone help? I’ve been at this for a bit and am having troubles, if you need more details feel free to ask, sorry this isn’t easy to explain.
The first +curtime is 6, and the second +curtime is 2.
When I switch the two around (2 and 6 instead of 6 and 2) my overlay is enabled when looking away, and disabled when looking at the entity, this is good because it is a visual of if the code is actually working, but ofcourse when I switch those two, the death timer stops working. Please help :suicide:

Well this obviously isn’t a slenderman related :v:

In ENT:CanVictimSeeUs() you don’t seem to be returning true or false. Or are you calling that farther down?

If you’re not returning true in that function anywhere then you’re just destroying the timers right after you create them.

It might be the way you are going about it - timers aren’t a great thing for this.

function ENT:Initialize( )
	--Other stuff
	self.StareTable = { }
	self.LowestWatcher = math.huge
	self.HighestWatcher = -math.huge
	self.Victim = NULL

function ENT:PopulateWatchers( )
	local k, v, delta
	self.LastCheck = self.LastCheck or CurTime( )
	delta = CurTime( ) - self.LastCheck
	self.LastCheck = CurTime( )
	self.LowestWatcher = math.huge
	self.HighestWatcher = -math.huge
	self.Victim = NULL
	for k, v in ipairs( player.GetAll( ) ) do
		if not self.StareTable[ v ] then
			self.StareTable[ v ] = 0
		self.StareTable[ v ] = math.Approach( self.StareTable[ v ], v:GetEyeTrace( ).Entity == self and 4 or 0, delta )
		self.LowestWatcher = math.min( self.LowestWatcher, self.StareTable[ v ] )
		self.HighestWatcher = math.max( self.HighestWatcher, self.StareTable[ v ] )
		if self.HighestWatcher == self.StareTable[ v ] then
			self.Victim = v

function ENT:Think( )
	self:PopulateWatchers( )
	if not IsValid( self.Victim ) or not self.Victim:Alive( ) then
	if self.HighestWatcher > 0 then
		self:PlayDead( )
		self:NextThink( CurTime( ) + 6 )
		self:BeCreepy( )
		self:NextThink( CurTime( ) + 2 )

You might want to consider not running console commands on people to accomplish things unless you need to - Player:Kill( ) can’t be stopped by aliasing kill to something else ( alias kill say i cannot die ), and the overlay can be turned off by the player just setting it to “” or something that isn’t a valid material.

An approach like what I show would allow you to avoid trying to manage a bunch of timers, but can obviously be improved upon.

Thanks, will try that out

How did I know it would be you of all people to beat me to this =P

Pretty much EVERYTHING Kogitsune said. The only difference in my suggestion was going to be use the dot product of the players EyeAngles() to test if they’re looking at your entity, but a player trace works just as well, it just needs to be a tad bit more precise.

Sorry to be like this, but if I added you on Steam do you think you could help me?
I’m having a bit of troubles with this