How to split players into 2 teams?

Hello! I have been trying to find a way to split players into 2 teams, can somebody help out with this?

I haven’t found a way do do this and have been trying to for an hour or so.

Perhaps this could help?
Team Balancing (roblox.com)

I’m also sure there are youtube tutorials out there.

1 Like

Here’s an example, posted before.

1 Like

I did not test this code but it might work (note that you will have to adapt this code for your own game)

local players = game.Players:GetPlayers()
local teamCount = #players % 2 --Checks if the count is even or odd

local extraPlayer

local teamAssignment = "A"

if teamCount == 1 then
	extraPlayer = table.remove(players,#players)
end

for i, teamMember in pairs(players) do
	if teamAssignment == "A" then
		teamAssignment = "B"
		teamMember.Team = YOUR_TEAM_HERE --Add your own team name here as a variable
	else
		teamAssignment = "A"
		teamMember.Team = YOUR_TEAM_HERE_NO_2 --Add your own team name here as a variable
	end
end

local teams = {YOUR_TEAM_HERE,YOUR_TEAM_HERE_NO_2}

if extraPlayer ~= nil then
	extraPlayer.Team = teams[math.random(1,2)]
end

Thanks! This really helps out!

1 Like