So I created the following function to randomize teams for a game I'm making, and it works for the most part. However, in some instances, it decides to put three people on one team and one on the other, which should not happen. Can I get any help on this? Thanks!
function randomizeTeams() local unrandomized, randomized = {}, {} for _,player in next, game.Players:GetPlayers() do table.insert(unrandomized, player) end math.randomseed(tick()) for i = 1, #unrandomized do table.insert(randomized, unrandomized[math.random(1,#unrandomized)]) end local count = 0 for _,player in next, randomized do if count%2 == 0 then player.TeamColor = game.Teams['Red'].TeamColor elseif count%2 == 1 then player.TeamColor = game.Teams['Blue'].TeamColor end count = count + 1 end end