Dividing players onto 2 teams

Hello! I’m trying to make a system dividing the players into 2 teams. I’ve already tried looking on the developer forums for this and found my answer but its script is beyond my comprehension. How would I simply do this? (without using Roblox teams)

Could you explain what you want a little more?

What do you mean “without using Roblox teams”?

Could you link the script you found that was beyond your comprehension?

without using the teams system Roblox has built-in this is the script

local function makeTeams(k)
local players = game.Players:GetPlayers()
local n = #players
shuffle(players)

local teams = {}
for i = 1, k do
	local team = {}
	local lo = math.floor((i-1) * n / k) + 1
	local hi = math.floor(i * n / k) + 1
	for j = lo, hi-1 do
		table.insert(team, players[j])
	end
	table.insert(teams, team)
end

return teams

end

What do you think of this? is more simple:

local Team1,Team2 = {},{}
local T = 1
for i,Player in pairs(game:GetService("Players"):GetPlayers()) do
	if T == 1 then
		table.insert(Team1,Player)
		T = 2
	else
		table.insert(Team2,Player)
		T = 1
	end
end
print(Team1)
print(Team2)
2 Likes

This post has a good way to shuffle a table, you could combine it with @SOTR654’s solution to re-shuffle teams.

1 Like

its a good idea but i want my code to be something i understand to the fullest