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

remove player from a table when they die?

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

3 comments

0

table.remove() will help.

0

yeah I'm using that, but how do i get the index of the player who died?

0

Hi Scryptol, I gave an answer that also shows how to find the index, hope that helped!

1 answer

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!

1 comment

0

thanks for helping me

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