Help with team systems

How would I go about splitting the teams evenly or close to even depending on the amount of players in game? There are two teams in the game.

Are the players automatically set in a team or can they decide on the team to go to depending on how full is it? How are you teaming the players so I can give an example that relates to what you want, but in the end it’ll probably boil down to comparing the amount of players in the teams with the total players in the game, seeing which has fewer and teaming the player to there

The teams will be auto assigned.

A basic example of this would be this

local players = game:GetService("Players")
local teams = game:GetService("Teams")

local redTeam = teams.Red
local blueTeam = teams.Blue

players.PlayerAdded:Connect(function(plr)
	local totalRed = #redTeam:GetPlayers()
	local totalBlue = #blueTeam:GetPlayers()
	
	if totalRed <= totalBlue then
		plr.Team = redTeam
	else
		plr.Team = blueTeam
	end
end)

When the player joins, it gets the total players for the 2 teams, if there are less or equal reds than blues, team them to red team, otherwise, team them to blue

1 Like

Thank you for this example but It’s a minigame type and I’d like to get the current amount of players in game so when new players join they’ll be set to a spectating team I added

The basic principal will still apply, when the minigame starts, team the players one by one, using what I did by getting the total players in both teams and teaming accordingly

For the spectating team, Just make it the only AutoAssignable team and the other 2 teams not AutoAssignable. Then, if you want the allow the spectators to join a team, when they click on a button to join the game, compare the players in both teams and team them in the correct team to keep equality

1 Like