Humanoid.Died is not working

I’m trying to make a punching bag that when it dies, it gives the player who killed it some strength. Through my combat system, I tag the model with an objectvalue named “Deb” and the value of it is set to the player who hit the punching bag. However, when I test it and I kill the humanoid in the punching bag, I am not getting any response from humanoid.died as the print(“humanoid died”) isn’t even showing up in the output. Does anyone know how I can fix this? If you need more information to help me, I will gladly provide it.

https://gyazo.com/6f44d444cfc21f0bc318943f307c0ba4

script.Parent.Humanoid.Died:Connect(function()
	print("Humanoid died")
	if script.Parent:FindFirstChild("Deb") ~= nil then
		local Killer = script.Parent.Deb.Value
		Killer.leaderstats.Strength.Value += 100
		print("Strength given.")
	end
end)

Are you sure the punching bag is alive in the first place?

1 Like

It has a health bar that starts at 100 and goes down as I punch it, so I would assume that it’s alive but is there any way to make sure?

Are you (also) sure that the health of the Punching Bag goes down to zero? It doesn’t count as a death if not.

It goes into the negatives, is that bad?

It shouldn’t go into the negatives… what are you using to kill it with??

You have to add a debounce to the thing your using to kill it with.

I’m using a punch to kill it. I can send you the code for that if needed.

Yeah, the code would be helpful.
Please send it.

Hello!
You did some errors in the script:

script.Parent.Humanoid.Died:Connect(function()
	print("Humanoid died")
	if script.Parent:FindFirstChild("Deb") ~= nil then
		local Killer = script.Parent.Deb.Value
		Killer.leaderstats.Strength.Value += 100
		print("Strength given.")
	end
end)

I won’t use an objectValue, but a stringValue, then the value is set to the player’s name?

Second: Killer.leaderstats.Strength.Value += 100 is wrong. Replace this line with Killer.leaderstats.Strength.Value = Killer.leaderstats.Sternght.Value + 100

Hope it helps :smiley:

Here’s the local script that fires the server event.

Player = game.Players.LocalPlayer
repeat wait() until Player.Character
Character = Player.Character

Tool = script.Parent

Enabled = true

Tool.Activated:Connect(function()
	if Enabled == true then
		script.Function:FireServer("Combat", Character.HumanoidRootPart.CFrame * CFrame.new(0,0,-2).p)
	end
end)

Here is the main script for animations and damage.

Enabled = true
Combo = 1

script.Parent.OnServerEvent:Connect(function(Player, Action, V1)
	local c = Player.Character
	local damage = Player.leaderstats.Strength.Value
	if Enabled == false then
		return
	end
	if Action == "Combat" then
		Enabled = false
		if Combo == 1 then
			Combo = 2
			local Track = Instance.new("Animation")
			Track.AnimationId = "rbxassetid://5577440669"
			local Anim = c.Humanoid:LoadAnimation(Track)
			Anim:Play()
		elseif Combo == 2 then
			Combo = 1
			local Track = Instance.new("Animation")
			Track.AnimationId = "rbxassetid://5577441980"
			local Anim = c.Humanoid:LoadAnimation(Track)
			Anim:Play()
		end
		wait(0.2)
		local Region = Region3.new(V1 - Vector3.new(2,2,2), V1 + Vector3.new(2,2,2))
		local RTable = workspace:FindPartsInRegion3(Region, nil, 20)
		for i, v in pairs(RTable) do
			if v.Parent:FindFirstChild("Humanoid") and v.Parent:FindFirstChild("Deb") == nil and v.Parent ~= c then
				local Deb = Instance.new("ObjectValue", v.Parent)
				Deb.Name = "Deb"
				Deb.Value = Player
				game.Debris:AddItem(Deb, 0.5)
				v.Parent.Humanoid:TakeDamage(damage)
				local S = Instance.new("Sound", v)
				S.SoundId = "rbxassetid://3932506625"
				S.PlaybackSpeed = math.random(80,120)/100
				S:Play()
			end
		end
		wait(0.31)
		Enabled = true
	end
end)

https://gyazo.com/fda5aaa0b364bd909790f035138046aa

replace the

v.Parent.Humanoid:TakeDamage(damage)

with

if v.Parent.Humanoid.Health =< damage then
    v.Parent.Humanoid.Health = 0
else
    v.Parent.Humanoid.Health = v.Parent.Humanoid.Health - damage
end

and tell me if that works.

These won’t fix my issues because my Humanoid.Died function isn’t even working. If I get the Humanoid.Died function to work and the script still does not work, I will try these though!

I’m not getting negative numbers for the humanoid health anymore, but Humanoid.Died is still not working because I’m not getting the print"humanoid died" in the output.

You can always change the humanoid.Died function to a
if humanoid.Health <= 0 then
statement.

Just tried this and it did not work.

put a while wait statement before the if humanoid.Health because it will only run as soon as the game is started

Is the “Deb” value a player instance? Or a Name?

Clearly in the post he said

So yes its a player, not a name.

1 Like

This worked but it keeps printing “humanoid died” hundreds of times.

use this as your script
local printed = false
while wait() do
if humanoid.Health <= 0 and not printed then
printed = true
print(texthere)
end
end

1 Like