Humanoid.Died buggy

So I want to add a death for each person after they die on the leaderstats. Here is my code:

humanoid.Died:Connect(function()
	game.Players[player.Name].leaderstats.Kills.Value = game.Players[player.Name].leaderstats.Kills.Value + 1
end)

For some reason, when the player gets killed their deaths go up to like 46,264 and I don’t remember Humanoid.Died firing forty thousand times.

2 Likes

issue with ur other code, not with died.

2 Likes

This is my other code:

script.Parent.Touched:Connect(function(h)
			local humanoid = h.Parent:FindFirstChild("Humanoid")
			if humanoid ~= nil and humanoid ~= script.Parent.Parent.Humanoid then
				humanoid.Health = humanoid.Health - 10
				humanoid.Died:Connect(function()
					game.Players[player.Name].leaderstats.Kills.Value = game.Players[player.Name].leaderstats.Kills.Value + 1
				end)
			end
1 Like

I think the problem is that you didn’t put a debounce on the .Touched.

local debounce = false
local death = false

script.Parent.Touched:Connect(function(hit)
    if debounce then return end
    debounce = true

    local humanoid = hit.Parent:FindFirstChild("Humanoid")
    if humanoid and humanoid ~= script.Parent.Parent.Humanoid then
        humanoid.Health -= 10

        humanoid.Died:Connect(function()
            if death then return end
            death = true

            game.Players[player.Name].leaderstats.Kills.Value += 1
            death = false
        end)
    end

    debounce = false
end)

I also added a debounce on the .Died because otherwise multiple of them would be running since you make multiple connections if the player touches the part more than once.

4 Likes

You should probaly add a debounce, since setting the health to 0 counts as “.Died”.

2 Likes

You are connecting alot of Humanoid.Died events to the same humanoid that each add one to your leaderboard. You should use a playeradded event and setup your .died connection in there.

1 Like