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