Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-4

How do I split up players?? ;/

Asked by 8 years ago

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

Log in to vote
8
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago
Edited 8 years ago

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
0
What if teams are uneven and you don't want to make it uneven? EzraNehemiah_TF2 3552 — 8y
0
Goul, it seems to not be working. You have gave me the jist of switching the value. Why is it not working though? PullAnAllNighter 8 — 8y
0
Are you setting your team values correctly? Goulstem 8144 — 8y
0
I am naming them Team1 and Team2 PullAnAllNighter 8 — 8y
View all comments (8 more)
0
It just does not work ;/ PullAnAllNighter 8 — 8y
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. Goulstem 8144 — 8y
0
I added a wait(15) PullAnAllNighter 8 — 8y
0
try adding ' repeat wait() until #game.Players:GetPlayers() >= 2 ' at the top, that will ensure atleast 2 players have loaded. Goulstem 8144 — 8y
0
still refuses to work ;/ PullAnAllNighter 8 — 8y
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. ScriptGuider 5640 — 8y
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.. PullAnAllNighter 8 — 8y
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? Goulstem 8144 — 8y
Ad

Answer this question