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

When selecting players for a game...?

When selecting players for a game from a table ... how do I remove all players from a table.

1 answer

✓ Accepted answer

There are multiple ways to do this.


###Way 1: Table.remove

The first option we have is to sort through the whole table and remove each entry. We can do this by a for statement, and using table.remove.

Example:

players = {"p1", "p2", "p3"}
for _,v in pairs(players) do
table.remove(v)
end

###Way 2: Functions.

If you are only using the table in one function (or adding to it, I should say) you can add this to your function. This example would reset the whole table when a new player joins:

game.Players.PlayerAdded:connect(function (nP)
players = {}
for _,v in pairs(game.Players:GetChildren()) do
table.insert(v)
end
end)

I am sure there are also other ways, but these are the immediate ones that come to mind.

##Hope I helped, ##Creative Energy

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