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]
✓ ANSWER ACCEPTED
How to Put 3 players in one team 4 in the other 6 in the other one?
1 answer
✓ Accepted answer
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
This discussion is preserved as it was. New answers, comments, and votes are closed.

9 comments
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.
Also, you should shuffle the list of players or they might always end up on the same team.
@ducwit there are issues with this I'm fixing it right now, I was rushing it for it was the end of lunch.
There we go should be working now.
I also forgot about the repetition issue so I did as you suggested :P
where should i paste this script at starter gui?
@Microsofts98 on the server, like ServerScriptService
@Danzlua THANKS
@Microsofts98 np :D dont forget to accept my answer if you like it ;p