How Can I Get This Code To Work?

Hello. For a gamemode I’m creating, I need a little help with something. You see, what this part of the code is supposed to show is to:
Get the players on both teams.
When a player dies, they move to the spectator team.
If the spectator team is full of all the players on one team, it says that the other team won, then generates a mapchange(for now mapchange has been replaced with ply:ConCommand).
Here’s the code(I’m not having an error with it, but instead I just don’t know how to get it to work the way I want it to):


function GM:PlayerDeath( ply, ent, att )

timer.Simple( 0, function()

if ply:IsValid() then

ply:SetTeam( TEAM_SPECTATOR )
ply:Spectate( OBS_MODE_ROAMING )

if team.NumPlayers( TEAM_SPECTATOR) == #team.GetPlayers then

PrintMessage( HUD_PRINTTALK, "One team has been eliminated! Round over." )

timer.Simple( 10, function() 

ply:ConCommand("respawn_entities")

end )

end

end

end)
end


Edit: The two teams I’ve created are called “Rebels” and “Combine” and their team numbers(not indexes) are (For Combine): 1, and(For Rebels): 2.

That’s now how you use

team.GetPlayers. Nothing past that if statement is going to be ran.

“I’m not having an error with it, but instead I just don’t know how to get it to work the way I want it to”
I know that isn’t how you use it. I need help adding onto the code and replacing stuff, not fixing something in it.

You would check one of the teams has no players, not if one team had players who were all previously in another team.

Ohhhh, right, better idea. Thanks, you’re right, checking if one team had no players would be a lot better.