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

Pick 6 random players out of a 16 Player Server?

Asked by
Uroxus 350 Moderation Voter
10 years ago

So how would I go about picking 6 Random players every time a new round begins and to put the rest of the players in the other team?

Thank you for your help in advance :)

1 answer

Log in to vote
3
Answered by
Asleum 135
10 years ago

Create a table containing all the players using GetChildren(). Then, choose a random player by indexing a random player from that table. Don't forget to remove the chosen players from the table, otherwise they can be chosen twice :

local Players = game.Players:GetChildren()

for i = 1, 6 do --Choose six players
ChosenPlayerIndex = math.random(#Players) --Chose a random player index
Players[ChosenPlayer].TeamColor = BrickColor.new("Bright blue") --Move the chosen player to the blue team
table.remove(Players, ChosenPlayerIndex) --Removes the player from the list so he can't be chosen again
end

(This script is supposed to be placed inside either game.Workspace or game.ServerScriptService, in a normal script)

Ad

Answer this question