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

How to randomly add someone to a table and then clear it?

Asked by
TofuBytes 500 Moderation Voter
10 years ago

I'm trying to randomly select a player from the ServerPlayers and then add them to the table called AlreadyChosen. Once all the players have been chosen once, the table will clear itself and run again. I'm lost on how I can do this. Any help please?

local ServerPlayers = game.Players:GetChildren()
local AlreadyChosen = {}

repeat  
ChosenJeff = math.random(1,#ServerPlayers)
until ServerPlayers[ChosenJeff].Name ~= AlreadyChosen
local JeffName = ServerPlayers[ChosenJeff].Name
table.insert(AlreadyChosen,JeffName)

Answer this question