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

Checking for player deaths, any help?

Asked by 8 years ago

I have this script, were I am trying to add the players to a table, and to check when one of those players dies. And when they do I need it to do something. Right now Im not sure how to check for player death, and adding the players to a table.

Here is the script:

local playerTable = {}
local c = game.Workspace.CurrentCamera

game.Players.PlayerAdded:connect(function (newPlayer)
    table.insert(playerTable, newPlayer)
    print(table)
end)

game.Players.PlayerRemoving:connect(function(leavingPlayer)
    table.remove(playerTable, leavingPlayer)
    print(table)
end)
wait(5)
for i, player in pairs(game.Players:GetChildren()) do
    player.PlayerValues.PlayerHealth.Changed:connect(function(HP)
        if HP == 0 then
            print'PlayerDied'           
            for i, v in pairs(game.Players:GetChildren()) do
                if v.Name == player.Name then
                    wait()
                elseif v:IsA'Player' then
                    wait()
                    if player.PlayerService.PlayerTeam.Value == BrickColor.new("Bright red")
                    and player.Character.Humanoid.Health == 0 then
                        wait()
                    else
                        wait()
                    end
                end
            end
        end
    end)
end

1 answer

Log in to vote
0
Answered by
Decemus 141
8 years ago
player.CharacterRemoving:connect(function(Removing)
end)
Ad

Answer this question