So, first let's get a table of all the players:
local plrs = game.Players:GetChildren()
Now, let's define two teams called Red Team and Blue Team:
local redTeam = {}
local blueTeam = {}
So, we need to divide the teams in half. We also need to use math.floor to get no decimals in case there is an odd number of players.
local plrsOnEachTeam = math.floor(plrs / 2)
Now, we put that amount of people on each team:
for i = 1,plrsOnEachTeam,1 do
table.insert(redTeam,#redTeam + 1,plrs[1])
table.remove(plrs,1)
end
for i =1,plrsOnEachTeam,1 do
table.insert(blueTeam,#blueTeam + 1,plrs[1])
table.remove(plrs,1)
end
if #plrs == 1 then
table.insert(redTeam,#redTeam + 1,plrs[1])
table.remove(plrs,1)
end
Hope this helped!