How to remove a player from a table when he dies

I want to make that whenever a player dies they get removed from the table how would i be able to make that?

elseif map:FindFirstChild("Survival") then
			roundType = "Survival"
			map.SurvivePart.Touched:Connect(function(hit)
			  if hit.Parent:FindFirstChild("Humanoid") then
			    local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
			    if not table.find(survivalwinners,plr.Name) then
						table.insert(survivalwinners,plr.Name)
2 Likes

oh i see that script minigame is from zingodev and also can i see the whole script

1 Like

The basics are yes, but i modified it alot.

Theres no need for the whole script i think, i just need to know how to remove a player from the table when he dies.

1 Like

u can use table.remove or u can put them on one other folder and name it finish so when they touch the survivepart the character’s parent can move on finish so when they die the character will go to workspace automatically

local connection
for _, player in pairs(Game:GetService("Players"):GetChildren())
     local char = player.Character
     connection = char:WaitForChild("Humanoid").Died:Connect(function() -- runs the function when player has died
          print(player.Name .. " has died!")
          if table.find(survivalwinners, player.Name) then -- wont run if the player isn't in the table
               connection:Disconnect() -- This part makes it so if the same player dies again the script wont run. This also reduces lag so yes. If you want to make it so the script keeps running even though the player has died once then remove this part
               local location = table.find(survivalwinners, player.Name) -- gets the location of player in table
               table.remove(survivalwinners, location) -- removes the player from tabl
          end
     end)
end
2 Likes

The second argument for table.remove is number position not the thing itself. It should be done like so:

if table.find(survivalwinners,plr.Name) then
local pos = table.find(survivalwinners,plr.Name)
table.remove(survivalwinners,pos)
end

Use table.remove() here is an example

local Winners = {}

table.remove(Winners, Player.Name)
local AlivePlayers = {} -- initialized table for all players
game.Players.PlayerAdded:Connect(function(player)
     player.CharacterAdded:Connect(function(character)
          table.insert(AlivePlayers,player.Name)
          local hum = character.Humanoid
          local connection
          connection = hum.Died:Connect(function() -- if they died naturally
          table.remove(AlivePlayers,table.find(AlivePlayers,player.Name))
          connection:Disconnect()
          end)
          connection = hum.Destroying:Connect(function() -- if they got deleted
          table.remove(AlivePlayers,table.find(AlivePlayers,player.Name))
          connection:Disconnect()
          end)
     end)
end)

Where exactly do i need to add this block of code?

if table.find(survivalwinners,plr.Name) then -- checks if the player is in the survivors table
table.remove(survivalwinners,table.Find(survivalwinners,plr.Name)) -- removes the player from the table
end

This wont remove the player when he dies, or does it?

no you have to add : Humanoid.Died:Connect(function()
or you could just check for his health : Humanoid.HealthChanged:Connect(function()
and another method : Humanoid:GetPropertyChangedSignal("Heatlh"):Connect(function()

The part where you want the player name to be removed when the player dies.
I would tell you exactly where but looking at the code you provided it is hard to tell where you want to achieve that.

1 Like

table.remove(Players, table.find(Players, Player))

Where ‘Player’ is a reference to the player that died and ‘Players’ is a reference to the table of ‘alive’ players.