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

When selecting players for a game...?

Asked by 9 years ago

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

1 answer

Log in to vote
1
Answered by 9 years ago

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

Ad

Answer this question