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

How to Put 3 players in one team 4 in the other 6 in the other one?

Asked by 7 years ago

I am creating a game i have to put 3 players in one team and in the other 4 and in other 6 any ideas? [Btw i am new at scripting]

1 answer

Log in to vote
0
Answered by
DanzLua 2879 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

Well lets do this, We will create a loop that will run for every player and add them to a team

Assuming you have a max number of 13 players,

--variables
local team1 = game.Teams.Team1
local team2 = game.Teams.Team2
local team3 = game.Teams.Team3

--shuffle
local players=game.Players:GetChildren()
local new = {} 
for i = #players, 1, -1 do
    local x = math.random(1, i)
    table.insert(new, players[x])
    table.remove(players, x)
end
players = new

--set
for i,v in pairs(players) do
    if i<=3 then
        v.Team=team1
    elseif i>3 and i<=7 then
        v.Team=team2
    elseif i>7 and i<=13 then
        v.Team=team3
    end
end

Make sure to change team, team2, and team3 to the teams in your game.

Hope this helped if you have any questions please ask me :D

0
The 'i>n' inequalities are redundant. Think about it: if the first condition fails, that means i > 3, so make the next one 'elseif i <=4'. If that fails, i is definitely > 4, so you can have plain 'else' on the end. duckwit 1404 — 7y
0
Also, you should shuffle the list of players or they might always end up on the same team. duckwit 1404 — 7y
0
@ducwit there are issues with this I'm fixing it right now, I was rushing it for it was the end of lunch. DanzLua 2879 — 7y
0
There we go should be working now. DanzLua 2879 — 7y
View all comments (5 more)
0
I also forgot about the repetition issue so I did as you suggested :P DanzLua 2879 — 7y
0
where should i paste this script at starter gui? MicrosoftS98 17 — 7y
0
@Microsofts98 on the server, like ServerScriptService DanzLua 2879 — 7y
0
@Danzlua THANKS MicrosoftS98 17 — 7y
0
@Microsofts98 np :D dont forget to accept my answer if you like it ;p DanzLua 2879 — 7y
Ad

Answer this question