adding spawn hook crashes server

What im trying to do is a basewars-like gamemode ( based on sandbox ). When i try to add spawn hooks, server crashes.

My code:
[LUA]for k,v in pairs(player.GetAll()) do
v:PrintMessage( HUD_PRINTTALK,“Build mod started! Please wait 5 seconds!”)

function buildm(V)
RunConsoleCommand(“sbox_noclip”, 1)
RunConsoleCommand(“sbox_godmode”, 1)
RunConsoleCommand(“sbox_maxprops”, 200)

timer.Create(“buildbaslama”, 5,1, buildm)


hook.Add(“PlayerSpawn”, “pSpawn”, buildm)

When i remove “hook.Add”, it works great, but i have to add that hook.

Why are you defining a function and creating a timer inside a loop?

timer was outside the loop, that was for try. i didnt know the problem was in hook.Add before.

Doing this:


Causes the hook “PlayerSpawn” to get called again. Basically creating an infinite loop.
Remove the v:Spawn() part and try again.

Oh thanks, while thinking what can i add else to my code different to Spawn(), i found great ideas to do.
Problem fixed.