Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I split up players?? ;/

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!

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

12 comments

0

What if teams are uneven and you don't want to make it uneven?

0

Goul, it seems to not be working. You have gave me the jist of switching the value. Why is it not working though?

0

Are you setting your team values correctly?

0

I am naming them Team1 and Team2

0

It just does not work ;/

0

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.

0

I added a wait(15)

0

try adding ' repeat wait() until #game.Players:GetPlayers() >= 2 ' at the top, that will ensure atleast 2 players have loaded.

0

still refuses to work ;/

1

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.

0

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..

0

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?

This discussion is preserved as it was. New answers, comments, and votes are closed.