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:

1table.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:

01game.Players.PlayerAdded:Connect(function(player)
02    player.CharacterAdded:Connect(function(char)
03        char.Humanoid.Died:Connect(function()
04            -- Loop through table
05            for i, v in pairs(game.Players:GetPlayers()) do
06                if v == player then
07                    table.remove(YourTable, i)
08                end
09            end)
10        end)
11    end)
12end)

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