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)
v:Spawn()
v:StripWeapons()
v:Give(“gmod_tool”)
v:Give(“weapon_physgun”)
end

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

end

hook.Add(“PlayerSpawn”, “pSpawn”, buildm)
[/LUA]

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:



v:Spawn()


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.