Team Bal. help

Alright, so i’m working on a test gamemode, and for some reason, this wont work:


function ES( ply )
local ES = math.random(3, 4)
	if ES == 3 then
	ply:SetTeam( 3 )
	end
	if ES == 4 then
	ply:SetTeam( 4 )
	end
	function SPAWN( ply )
		Republic = team.NumPlayers( 3 )
		Cis = team.NumPlayers( 4 )
		if Republic > Cis then
			ply:SetTeam( 4 )
		end 
		if Cis > Republic then
			ply:SetTeam( 3 )
		end
	end
end

Players join, and it puts them on one team, and i’m on the other, it doesn’t let them spawn as my team.

-snip- silly me, page didn’t load fully and I didn’t see the whole code

Try this:


 local rand = math.random(1,2)
if rand == 1 then
if team.NumPlayers(3) < team.NumPlayers(4) then
ply:SetTeam(3)
end
end
if rand == 2 then
if team.NumPlayers(4) < team.NumPlayers(3) then
ply:SetTeam(4)
end
end


EDIT: Forget the last part… i just noticed you are doing it when someone joins… not when a amount of players join. Just do that ^

Here’s a thing you might like for checking balance:

Hmm I never knew there was something like that…

Hmmmm so I just delete the old code and replace it with team.BestAutoJoinTeam( 3, 4 )
?

Just wanted to point out that in the original code you had



local ES = math.random(3, 4)
if ES == 3 then
	ply:SetTeam( 3 )
end
if ES == 4 then
	ply:SetTeam( 4 )
end


which could easily be changed to



local ES = math.random(3, 4)
ply:SetTeam(ES)


He wants the teams to be balanced, not just people randomly placed…