Well, having the whole randomness of the team selection kinda contradicts the ability to keep it balanced.
If you want a better way to organize your players into different teams in a balanced manner, here's some code I whipped up:
local TeamService = game:GetService'Teams'
local Players = game:GetService'Players'
Players.PlayerAdded:connect(function(Player)
local NumPlayers = Players.NumPlayers
local Teams = #TeamService:GetTeams()
Player.TeamColor = TeamService[NumPlayers%Teams == 0 and Teams or NumPlayers%Teams].TeamColor
end)
How it works
Basically all we're doing here is getting the remainder of #players / #teams, and assorting the player to that index in GetTeams
Sorry if this wasn't quite the answer you were looking for, but this is just based off what I understood from your question. If this wasn't exactly what you had in mind, leave a comment and I'll update my answer to whatever questions / clarifications you'd like to remark.
1 comment
always randomly choose the odd numbered player and fill other team until its even