Playersiderelated script

Hey guys, its me again.
Since im still learning how to do all that stuff, heres another question.
This time im trying to do something that runs all the time a player is online (timer), and get removed on disconnect. The thing is, im not sure how. Thats what i have already:


function OnPlayerSpawn()

	local delay = 10

	timer.Create( "Thing", delay, 0, function(ply)
	end)
end
hook.Add( "PlayerInitialSpawn", "Incoming", OnPlayerSpawn)

local function DisconnectedCheck()
	self:timer.Remove( "Thing" )
end
hook.Add( "PlayerDisconnected", "Dischconnect", DisconnectedCheck, -20 )


Is that correct? Does something else needs to be added there?

[editline]26th July 2015[/editline]

Also, it happened to me ever since. Why do i get this error


attempt to call field 'notifyAll' (a nil value)


for example for that?


DarkRP.notifyAll( 3, 5, "Message")


  1. Localise that OnPlayerSpawn function.
  2. Make your timer name unique to the player (SteamID, UID, something) or else others spawning will override it
  3. The ply argument isn’t provided to the timer, but the PlayerSpawn function.
  4. You know 0 for your timer argument makes it repeat infinitely, right?
  5. Remove the self in front of timer.Remove.
  6. Why did you feed the fourth argument of -20 into the hook.Add?

[editline]26th July 2015[/editline]

notifyAll is serverside only

Why would each player need its own timer, instead of one timer that loops through all players?



timer.Create("SuperSpecialTimer",10,0,function()
     for k, v in pairs(player.GetAll()) do
          --code here! if you wanted all players to die every ten seconds you would do:
          --v:Kill()
     end
end)


For this scripts its important to have every player have its own timer.
The next question would be, how do i Localise(?!) the OnPlayerSpawn function, and how do i make it unique to each player?
And yus i know its infinite. Its meant to loop infinite, for the session a players online.

Thats what i do have corrected with my gained knowledge:



function OnPlayerSpawn(ply)

	local delay = 10

	timer.Create( "Thing", delay, 0, function()
	end)
end
hook.Add( "PlayerInitialSpawn", "Incoming", OnPlayerSpawn)

local function DisconnectedCheck()
	timer.Remove( "Thing" )
end
hook.Add( "PlayerDisconnected", "Dischconnect", DisconnectedCheck ) 

[editline]26th July 2015[/editline]

[editline]26th July 2015[/editline]

Anyone a clue how i could get the script running?

Look at what you did with DisconnectedCheck. That’s a local function.