local Players = game:GetService("Players")
local Workspace = game:GetService("Workspace")
local ReplicatedStorge = game:GetService("ReplicatedStorage")
local Event = ReplicatedStorge:WaitForChild("DisplayRole")
local Killer = nil
local Survivor = {}
function PickPlayers()
Killer = nil
Survivor = {}
local PlayersGroup = Players:GetChildren()
local KillerID = math.random(1, #PlayersGroup)
for i, v in pairs(PlayersGroup) do
if i == KillerID then
Killer = v.Name
break
end
end
for i, v in pairs(PlayersGroup) do
if i == KillerID then
else
table.insert(Survivor, v.Name)
end
end
Event:FireClient(Players[Killer], "Jason")
for i, v in pairs(Survivor) do
Event:FireClient(Players[v],"You are survivor")
end
while wait() do
for i,v in pairs(Survivor)do
print(i, v) -- This is where i need help
end
end
end
PickPlayers()
✓ ANSWER ACCEPTED
When I print out the table it doesn't update survivors if they leave the game or die?
1 answer
✓ Accepted answer
To check if a player has died or left the game you can use this code:
for i, v in pairs(Survivor) do
local player = Players:FindFirstChild(v)
if player then
local character = Workspace:FindFirstChild(player.Name)
if character and character:FindFirstChild("Humanoid") then
if character.Humanoid.Health < 0 then
--do stuff when player has died
end
end
else
--do stuff when player leaves
end
end
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
instead of doing Players:GetChildren() use player:GetPlayers()