Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Equal Team Shuffling, help!?

function shuffleTeams()
	local curteam=1
	for i,v in pairs(game.Players:GetPlayers()) do
			if curteam==1 then
				curteam=2;
				v.TeamColor=BrickColor.new("Bright red")
			else
				curteam=1;
				v.TeamColor=BrickColor.new("Bright blue")
			end
   	 end
end


while true do
	wait(15)
	shuffleTeams()

end

well this is the script, i run in studio with 4 players. no error messages, but no team changing...

If this is a bad method of random, equal team shuffling, please show me the correct method.

1 comment

0

I could have told you why, lol

1 answer

✓ Accepted answer

I made a slight mistake in that code, all you have to do Is change the curteam to a random number between 0 and 1.

seed=1234
math.randomseed(seed)
function shuffleTeams()
    local curteam=math.random(0,1)
    for i,v in pairs(game.Players:GetPlayers()) do
            if curteam==1 then
                curteam=2;
                v.TeamColor=BrickColor.new("Bright red")
            else
                curteam=1;
                v.TeamColor=BrickColor.new("Bright blue")
            end
     end
end


while true do
    wait(15)
    shuffleTeams()

end


Only problem is it will keep the same players on the same teams.

This discussion is preserved as it was. New answers, comments, and votes are closed.