Player Spawning problem

Currently Trying to get my players to ethier spawn as team one or team two [lua]function GM:PlayerInitialSpawn( ply )

if team.NumPlayers(1) > team.NumPlayers(2) then
ply:SetTeam( 1 )
ply:SetTeam( 2 )

end [/lua]

It currently only sets them as team two instead of team one all the time. Whats wrong here?

What I can deduct from reading your code is that when one team has more players than the other, it puts them in this very team and not the other, as you probably intended it.

Inverse the greater than sign ?

Make > into >= or you could change the > to <

Team 1 is never going to have more players than team 2 as they both start off a zero.

No one notices the fact that he is doing this like wire’s expression two.
Get rid of the {}**

Or any programming language :V

No programming language I’ve used that has {}'s for if statements also has then…
And according to the Wire Expression2 page on the wiki (, neither does it. So everyone’s wrong!

And if you didn’t get how to fix the code, this is how I would do it:
function GM:PlayerInitialSpawn( ply )
if team.NumPlayers(1) > team.NumPlayers(2) then – If team 1 has more…
ply:SetTeam( 1 ) – Set team to 1
elseif team.NumPlayers(1) < team.NumPlayers(2) then – If team 2 has more…
ply:SetTeam( 2 ) – Set team to 2
elseif team.NumPlayers(1)==team.NumPlayers(2) then – if they are equal
ply:SetTeam(math.random(1, 2)) – Set it randomly
I know you don’t need that many checks, but whatever. I think it would be better to set their team randomly than always set it to team 1/2 when empty, anyways, but that’s just me.

Wow. Dumb(:
ALL programming languages use {}'s for if-statements. Scripting languages on the other hand are different.(: