Dinpey
(Dinpey)
January 16, 2021, 6:22pm
1
Is it possible to make this also work with people disconnecting and dying at the same time?
function died(playerName, humanoid)
if humanoid and humanoid.Health == 0 then
for i, v in pairs(survivors) do
if v == playerName then
table.remove(survivors, i)
end
end
end
end
Any help is appreciated.
rapmilo
(rapmilo)
January 16, 2021, 6:28pm
2
Wrap code with triple ` to format. Makes things much more readable.
You’ll want to connect to this function whenever a player leaves the game and when a humanoid dies. This might help:
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(chr)
local humanoid = chr:WaitForChild("Humanoid")
humanoid.Died:Connect(function()
died(plr)
end)
end)
end)
Players.PlayerRemoving:Connect(died)
You will also need to adjust your function to take the player object as input
function died(plr)
local ind = table.find(survivors, plr.Name)
if ind then
table.remove(survivors, ind)
end
end
3 Likes
Dinpey
(Dinpey)
January 16, 2021, 7:41pm
3
thanks for helping! This will help alot