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

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

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

✓ 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

9 comments

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.

0

Also, you should shuffle the list of players or they might always end up on the same team.

0

@ducwit there are issues with this I'm fixing it right now, I was rushing it for it was the end of lunch.

0

There we go should be working now.

0

I also forgot about the repetition issue so I did as you suggested :P

0

where should i paste this script at starter gui?

0

@Microsofts98 on the server, like ServerScriptService

0

@Danzlua THANKS

0

@Microsofts98 np :D dont forget to accept my answer if you like it ;p

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