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

Removing players from a table?

Asked by 8 years ago

Hi, in my script it kills all the players in this table then it removes all the players from the table. But when it gets to table.remove() it doesn't work. Can you help? Here's my script:

    for _, player in pairs(game.Players:GetChildren()) do
                for _, player in ipairs(playersingame) do
                    killplayers()
                    table.remove(playersingame, player)
                    print("test2")
                end
                player.PlayerGui.TextGui.Timer.Text = "You won!"
                player.PlayerGui.TextGui.Info.Text = "You succesfully disabled the bomb! Everyone gets 15 points!"
            end
            print("You won")

1 answer

Log in to vote
0
Answered by 8 years ago

This is a more correct version, based on what I understand the intent of the code to be.

playersInGame = {} --reset the table
for _, player in pairs(game.Players:GetChildren()) do --loop through all players
    killPlayers() --It's generally good practice to use camelCase. 
    --Capitalize the first letter of each word except the first word

    print("test2")
    player.PlayerGui.TextGui.Timer.Text = "You won!" --not exactly sure what this is for
    player.PlayerGui.TextGui.Info.Text = "You successfully disabled the bomb! Everyone gets 15 points!"
end

print("You won")
Ad

Answer this question