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

How can I detect when a player dies?

Asked by 8 years ago
local ID = 131149175

game.Players.PlayerAdded:connect(function(Player)
    wait(1)
    Player.Character.Humanoid:Died():connect(function()
        local s = Instance.new("Sound", Player:WaitForChild("PlayerGui"))
        s.SoundId = "rbxassetid://" ..ID.. ""
        s.Looped = true
        s:Play()
    end)
end)

I am trying to make it play a sound when the player dies. 21:44:16.199 - ServerScriptService.Script:5: attempt to call method 'Died' (a userdata value) 21:44:16.201 - Stack Begin 21:44:16.203 - Script 'ServerScriptService.Script', Line 5 21:44:16.205 - Stack End

0
Oh, and the only thing you did wrong was "()" beside Died on line 5 deputychicken 226 — 8y

1 answer

Log in to vote
1
Answered by 8 years ago
wait(4) -- Let errythin load
while wait() do
    for i, v in pairs(game.Players:GetChildren()) do
        repeat wait() until v.Character ~=nil
        local Char = v.Character
        local Hum = Char:FindFirstChild("Humanoid")
        Hum.Died:connect(function()
            print(v.Name .. " Has Died :(")
        end)
    end
end
0
Deputy, what does the v and i mean in your script? james24dj 90 — 8y
0
Doesn't work at all... BinaryResolved 215 — 8y
0
Ok, think back to 6th grade science. I is the independent and v is the dependent. i is the # of which the child is in Players and v is the actual thing. deputychicken 226 — 8y
0
Sorry, I fixed it just in case you want to use this one too cx deputychicken 226 — 8y
Ad

Answer this question