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

Humanoid died event not working?

Asked by
Mr_Unlucky 1085 Moderation Voter
5 years ago

I'm making a script where when the humanoid dies, then it awards him/her points. However, it doesn't. Help?

game:GetService('Players').PlayerAdded:connect(function(player)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            player.leaderstats.Explosions.Value = game.Players.LocalPlayer.leaderstats.Explosions.Value + 1
            player.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value + 10
        end)
    end)
end)
0
Please provide more information. Where is it located, and script type? User#19524 175 — 5y
0
It's located in the StarterPlayerScripts, and it's a local script. Mr_Unlucky 1085 — 5y
0
Are there any errors WeBuiltOurOwnWorld 6 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

PlayerAdded runs when a new player joins the game. However, the local script runs instantly, so it would instead wait for another player to join. You shouldn't be using PlayerAdded on the client anyways. Just place your script in a server script in `Server

game:GetService('Players').PlayerAdded:Connect(function(player)
    player.CharacterAdded:Connect(function(character)
        character:WaitForChild("Humanoid").Died:Connect(function()
            player.leaderstats.Explosions.Value = game.Players.LocalPlayer.leaderstats.Explosions.Value + 1
            player.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value + 10
        end)
    end)
end)

On a side note, switch to :Connect() as :connect() is deprecated and should not be used in new work.

0
ye Vulkarin 581 — 5y
Ad

Answer this question