I have absolutely no clue on how to do this, I have ask multiple people on the scripting Fourms and no one can give me absolute help. I want to know how to split the players in half so if I have 9 people there are 5 people on 1 team and 4 on the other team. I literally have 0 clue how to do this. Please help me!
COMMUNITY QUESTION
How do I split up players?? ;/
1 answer
If you have simply two teams, you can use a bool switch. This is just a value that you will turn on and off while iterating through all your players. You check it to decide which team the current player will be assigned to.
ex;
local bool = false; --It's off rn
local players = game.Players:GetPlayers() --This is your table of players
local team1 = game.Teams.Team1 --This is your first team
local team2 = game.Teams.Team2 --This is your second team
--Now, iterate through your table.
for _,v in next,players do
bool = not bool --Switch the bool!
--Now, check the current value to decide the team.
if bool then
v.TeamColor = team1.TeamColor
else
v.TeamColor = team2.TeamColor
end
end
If you want to reduce the code even more, apply some statement logic :D
for _,v in next, players do
bool = not bool
v.TeamColor = ((bool1 and team1.TeamColor) or team2.TeamColor)
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

12 comments
What if teams are uneven and you don't want to make it uneven?
Goul, it seems to not be working. You have gave me the jist of switching the value. Why is it not working though?
Are you setting your team values correctly?
I am naming them Team1 and Team2
It just does not work ;/
Okay.. when are you applying this code to your game? If it is running at the start of the server then there are no players to sort.
I added a wait(15)
try adding ' repeat wait() until #game.Players:GetPlayers() >= 2 ' at the top, that will ensure atleast 2 players have loaded.
still refuses to work ;/
This isn't a request site, you should be doing your part in figuring out what's wrong in your code as well, instead of just copying and pasting what people give you.
I know but like I said, I have 0 clue on how too. I have been trying to figure it out for weeks now. I have absolutely 0% clue. Ive learned alot from what hes showing me, I would just like to know the full code to study it..
Welll... i've provided almost an exact solution for you bud. Only thing ya gotta figure out is how to apply it to your game. I'm not sure where you're going wrong, I replicated the situation in studio and it worked fine. Do your teams have different TeamColors from one another?