How to Evenly Sort 4 Teams

Hi, I am trying to make a TDM game where players get sorted into four teams. I have been trying to find out how to do it for a while now, and the best I found was how to sort 2 Teams.

Here is the code for the two teams:

for i, plr in ipairs(game.Players:GetPlayers()) do
	if i%2 == 0 then
		plr.Team = teams.Red
	else
		plr.Team = teams.Blue
	end
end

If someone could help me make this work for four teams that’d be great. I just don’t know how to do it.
Any help is appreciated! :slight_smile:

What you have is a good start, you can just expand it to use four teams.

local ts = game:GetService("Teams")
local teams = {
	ts.Red,
	ts.Blue,
	ts.Yellow,
	ts.Green
}
for i, plr in ipairs(game.Players:GetPlayers()) do
	plr.Team = teams[(i % 4) + 1] -- arrays in Roblox start at 1
end
2 Likes

Thanks so much! I’ve been trying to do this for a while now, and now it works!