Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

When I print out the table it doesn't update survivors if they leave the game or die?

Asked by 4 years ago
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()
0
instead of doing Players:GetChildren() use player:GetPlayers() HappyTimIsHim 652 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago

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
Ad

Answer this question