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

how do i make a script that detects when the player dies and prints out value?

Asked by 6 years ago

i.e if Player health == 0 then print('ded') end

2 answers

Log in to vote
0
Answered by
DevNetx 250 Moderation Voter
6 years ago

You can do this with the Humanoid.Died event.

Read more here

i.e

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            print(player.Name .. " has died!")
        end)
    end)
end)
0
ty RealRexTerm 21 — 6y
Ad
Log in to vote
0
Answered by 6 years ago

Hey RealRexTeam,

The humanoid has a .Died event that you can use to detect when the player dies. I recommend just attaching it to the .CharacterAdded() function so that it runs at all times while the player is alive and it is well formatted that way. Here, I'll show you an example of it below.

Script

local plrs = game:GetService("Players"); -- The players service

plrs.PlayerAdded:Connect(function(plr) -- PlayerAdded anonymous function with parameter of the player.
    plr.CharacterAdded:Connect(function(char) -- CharacterAdded anonymous function with parameter of the player.
        local hum = char:WaitForChild("Humanoid"); -- The humanoid in the Character.
        hum.Died:Connect(function() -- .Died anonymous function
            print("Humanoid has died.") -- Prints "Humanoid has died." 
        end) -- end for .Died function.
    end) -- end for .CharacterAdded function.
end) -- end for .PlayerAdded function

Well, I hope I helped and have a nice day.

~~ KingLoneCat

Answer this question