hook keypress error

Hi I made a hook using the wiki…it should do something when I use IN_USE…it works well if I use print function (for checking if it works) but if I refer to self:StartActivity or similar it says


attempt to index global 'self' (a nil value)

I have already tried making a variable and using it in runBehaviour with elseif statment but it just doesn’t do anything…these are the codes:

this is the first that gives the console error


hook.Add( "Tick", "test", function()
	if ( Entity( 1 ):KeyPressed( IN_USE ) ) then
	if arrest then	
self:StartActivity(ACT_RUN)
self:ChaseEnemy()
	end
	end
end )

this is the second one


 elseif follow then
			self:StartActivity(ACT_WALK)
			self.loco:SetDesiredSpeed(150)
			self:ChaseEnemy()
			self:StartActivity(ACT_IDLE)   -----runbehaviour's part


hook.Add( "Tick", "test", function()
	if ( Entity( 1 ):KeyPressed( IN_USE ) ) then
	if arrest then	
follow = true
	else 
follow = false
	end
end
end )


if you need other part of code (for example what arrest variable is) tell me …

self is nil because it’s inside of a hook; change it to Entity(1) instead. Or use PlayerTick

thanks for the reply… I tried replacing self but entity(1) but now it gives me another error


attempt to call method 'StartActivity' (a nil value)


I thought that Entity(1) was the player and not the npc so maybe this is the reason why it doesn’t work…but I’m not sure…I need to refer about the npc and not the player…I want the npc to change his behaviour when I press E…