So if I have a block of code that creates active contestants:
ActiveContestants = {}
for _, player in pairs(Contestants) do
if player then
local Character = player.Character
if Character then
local MatchTag = Character:FindFirstChild("MatchTag")
local Humanoid = Character:FindFirstChild("Humanoid")
if MatchTag and Humanoid and Humanoid.Health > 0 then
table.insert(ActiveContestants, player)
end
end
end
end
end
How would I make something that removes the player from the table on the death of the player
function NewCharacter(KilledPlayer, Character)
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid then
Humanoid.Died:connect(function()
-- Would I put something here like:
table.remove(ActiveContestants, KillerPlayer)
end)
end
end
I pretty much want the player to be removed from the table when they die or if the matchtag is no longer in their character. I'm not sure how to go about this but a problem I am thinking will happen is if someone resets without a matchtag then it will error.

1 comment
If you want to use table.remove, then you need to have the place index as the second parameter