Delayed Spawning Code Needs Fixing

[lua]

--------------------THIS CHUNK OF THE CODE IS IN init.lua------------------
function GM:DoPlayerDeath( ply, attacker, dmginfo )
ply:CreateRagdoll();
ply:AddDeaths(1);
RunConsoleCommand(“check_alive”);
end

function check_alive(ply)
if !ply:Alive() then
Msg(“check_alive reached successfully.”);
RunConsoleCommand(“team_death”);
else
Msg(“How the hell did this happen?”);
end
end
concommand.Add(“check_alive”, check_alive);

function team_death(ply)
ply:Spectate(4);
ply:SetTeam(4);
ply:Freeze(true);
ply:PrintMessage(HUD_PRINTTALK, "[FistFight]You have died, "…ply:Nick());

	timer.Create( "deathtimer", 10, 1, function()
	RunConsoleCommand("ff_start")
	end )

end
concommand.Add(“team_death”, team_death);
------------------END OF init.lua CHUNK-------------------------

------------------THIS CHUNK IS IN cl_init.lua------------------
function set_team()

Ready = vgui.Create( “DFrame” )
Ready:SetPos( ScrW() / 2, ScrH() / 2 )
Ready:SetSize( 175, 75 )
Ready:SetTitle( “Respawn?” )
Ready:SetVisible( true )
Ready:SetDraggable( false )
Ready:ShowCloseButton( false )
Ready:MakePopup()

ready1 = vgui.Create( “DButton”, Ready )
ready1:SetPos( 20, 25 )
ready1:SetSize( 140, 40 )
ready1:SetText( “Yes” )
ready1.DoClick = function()

RunConsoleCommand( “ff_team2” )
Ready:SetVisible( false )
end
end

concommand.Add( “ff_start”, set_team )
------------------END OF cl_init.lua CHUNK-------------------------
[/lua]

What works:
-If you kill yourself the code counts down 10 seconds in a frozen unspectated mode, and then a prompt comes up asking you if you want to respawn.

-If you get killed you get placed in a 1st spectate mode following other players around for 10 seconds until you can respawn again.

What doesnt work:
-If you kill a player the “how the hell did this happen?” part of the “check_alive” function runs and it completely skips out of the “team_death” function.

Why doesn’t the check_alive function work for the other player also? How could I write this without all the console commands?

Why check_alive a console command? It’s a function on the server, there’s no need for console commands. If you have it as a console command the ply variable won’t be valid…

Wait, you’re using console commands everywhere D:, why?

How could I do it without console commands?

-------------------THIS CHUNK OF THE CODE IS IN init.lua------------------
[LUA]
function GM:DoPlayerDeath( ply, attacker, dmginfo )
ply:CreateRagdoll();
ply:AddDeaths(1);
ply:Spectate(4);
ply:SetTeam(4);
ply:Freeze(true);
ply:PrintMessage(HUD_PRINTTALK, "[FistFight]You have died, "…ply:Nick());

	timer.Create( "deathtimer", 10, 1, function()
	ply:ConCommand("ff_start")
	end )

end
[/LUA]

------------------END OF init.lua CHUNK-------------------------

------------------THIS CHUNK IS IN cl_init.lua------------------
[LUA]
function set_team()

Ready = vgui.Create( “DFrame” )
Ready:SetPos( ScrW() / 2, ScrH() / 2 )
Ready:SetSize( 175, 75 )
Ready:SetTitle( “Respawn?” )
Ready:SetVisible( true )
Ready:SetDraggable( false )
Ready:ShowCloseButton( false )
Ready:MakePopup()

ready1 = vgui.Create( “DButton”, Ready )
ready1:SetPos( 20, 25 )
ready1:SetSize( 140, 40 )
ready1:SetText( “Yes” )
ready1.DoClick = function()

RunConsoleCommand( “ff_team2” )
Ready:SetVisible( false )
end
concommand.Add( “ff_start”, set_team )
[/LUA]