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)
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
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)
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
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.