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

remove player from a table when they die?

Asked by 4 years ago

How do I get a table of all of the players in the server, then when one dies, remove that player from the table?

0
table.remove() will help. Dovydas1118 1495 — 4y
0
yeah I'm using that, but how do i get the index of the player who died? Scryptol 2 — 4y
0
Hi Scryptol, I gave an answer that also shows how to find the index, hope that helped! PhantomBrix 40 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

I don't know what you're scripting or how your game is setup but humanoids have a Died event which you could use.

You're going to need:

table.remove(NameOfTable, PositionInTable)

The only problem I see is that you are going to need to find the player's position in the table, I haven't tested this but maybe try:

game.Players.PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(char)
        char.Humanoid.Died:Connect(function()
            -- Loop through table
            for i, v in pairs(game.Players:GetPlayers()) do
                if v == player then
                    table.remove(YourTable, i)
                end
            end)
        end)
    end)
end)

If you want an explanation on how this works then I'll be happy to give one.

Hope this helps!

0
thanks for helping me DevvUnknown 3 — 4y
Ad

Answer this question