I am making a game where the players can pick their teams, but theres a problem. All the players can just go on one team. What can I do to make the teams even and stop everyone from just joining one team.
local function countTeams( player ) local rteam = 0 local bteam = 0 local neutral = 0 for k,v in pairs(game.Players:GetChildren()) do if v ~= player then if v.Neutral then neutral = neutral + 1 elseif v.TeamColor == teamRed then rteam = rteam + 1 elseif v.TeamColor == teamBlue then bteam = bteam + 1 else neutral = neutral + 1 end end end return rteam, bteam, neutral end
Divide the number of players in the game by the number of teams and round up. Make sure that if there are that many players on one team, you can't join that team unless someone leaves it.