When the game starts, it's supposed to team players on red, and blue and it doesn't do so. Can someone help me out? Is the function not proper?
function teams()
local balanceTeams = function(players, teams, randomize, callback)
for key = 1, #players do
local value = table.remove(players, randomize and math.random(#players) or 1);
if (not callback) or callback(key, value) then
value.TeamColor = teams[(key % (#teams + 1)) + 1];
end
end
end;
balanceTeams(
players:GetPlayers(), -- List of all players
{BrickColor.new("Bright red"), BrickColor.new("Bright blue")}, -- List of all teams
true -- Should it be random or not?
);

1 comment
Try adding game.Players.PlayerAdded:connect(teams) to the bottom of your script.