Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Humanoid died event not working?

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)

3 comments

0

Please provide more information. Where is it located, and script type?

0

It's located in the StarterPlayerScripts, and it's a local script.

0

Are there any errors

1 answer

✓ Accepted answer

###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.

1 comment

0

ye

This discussion is preserved as it was. New answers, comments, and votes are closed.