Player Freeze on spawn

I’m trying to make a script where if someone spawns, they automatically freeze. I know for freezing players is player:Lock(), but I don’t know how to make a command execute when spawning. (Sorry I’m such a noob.)

wiki.garrysmod.com/page/hook/Add

Hook to PlayerSpawn using code found ^

Also I think you should use Freeze()

Yeah, I just realized Player.Freeze() would be a bit easier.

To simplify:
[lua]
function GM:PlayerSpawn( ply )
ply:Freeze( true )
end
[/lua]

Use hooks instead of Gamemode functions.

Why does GM13 code have to be different from GM12?

Figured he was making a gm

Coincidentally I set this up a week ago.
[lua]timer.Create(“FreezeTime”, 0.5, 0, function()
for _,v in pairs(player.GetAll()) do
v:Freeze(true)
end
end)
timer.Simple(60, function()
timer.Stop(“FreezeTime”)
for _,v in pairs(player.GetAll()) do
v:Freeze(false)
v:Spawn()
end
timer.Start(“RoundTimer”)
print(“round start”)
end)[/lua]

[editline]a[/editline]
If you’re going to use hooks, use something like this instead:
[lua]hook.Add(“PlayerSpawn”, “FreezeTime”, function()
for _,v in pairs(player.GetAll()) do
v:Freeze(true)
end
end)
timer.Simple(60, function()
timer.Stop(“FreezeTime”)
for _,v in pairs(player.GetAll()) do
v:Freeze(false)
v:Spawn()
end
timer.Start(“RoundTimer”)
print(“round start”)
end)[/lua]

I’ve already gotten what I’ve wanted, this is the final result.



function GM:PlayerSpawn(ply)
	if not ply:IsSuperAdmin() then
	ply:Lock()
	print("Frozen while in menu.")
end
end