Humanoid.Died is not working

I have a server script inside my NPC which is located in the workspace inside a folder. The main job of the script is to run some code when the NPC dies, it was working perfectly fine today but for some reason when I was playing the game it suddenly stopped working with no errors in the output. I checked that the NPC’s Health is on 0, but however, it still didn’t work, and the “Humanoid.Died” event isn’t firing.

3 Likes

Have you tried Humanoid.Died:connect(function()?

3 Likes

Thanks for the clear explanation of what the problem is but could you provide a clear image of the problem and code samples.

1 Like
Humanoid.Died:Connect(function()
	wait(5)

	local DummyClone = DummyStorage:Clone()
	DummyClone.Name = Dummy.Name
	DummyClone.Humanoid.MaxHealth = Humanoid.MaxHealth
	DummyClone.Humanoid.Health = Humanoid.MaxHealth
	DummyClone.Parent = workspace.TrainDummies
	DummyClone:SetPrimaryPartCFrame(Dummy.HumanoidRootPart.CFrame)

	script.Parent:Destroy()
end)

1 Like

I don’t know, but did you update the game?

1 Like

The game was updated 1 hour ago.

1 Like

In the top left of studio, click file > publish to roblox and it should work

2 Likes

I just tried that, it didn’t work because I already published the game and its not a file.

1 Like

Weird, can you copy-paste this same script into another one?

1 Like

I have many NPCs in the game and they are all in one folder, what I did to save some time is clone the NPCs script and parent it to the model using another script that does that. So I can’t copy & paste it since it’s in all the NPCs.

1 Like

Is that the whole script? Because i don’t see the humanoid variable being declared.

Could you please show your full code? Maybe there is a problem above the written code?

1 Like

No, but the Humanoid is defined in the script before.

I think I found the problem!

As you stated you are connecting to this event through the server with a server script.

And I’m guessing you added prints to check if the NPC died but was changing the value of the health on the client instead of the server.

Here’s what I mean the server script isn’t connecting probably because your changing the health on the client and not the server.

I recommend you switch to the server then try again.
image
to
image

Then send the full script bruh

local Dummy = script.Parent
local Humanoid = Dummy:WaitForChild("Humanoid")

local SS = game:GetService("ServerStorage")
local RP = game:GetService("ReplicatedStorage")

local StatsFolder = RP:WaitForChild("Stats")
local QuestsFolder = SS:WaitForChild("Quests")

local DummyStorage = SS:WaitForChild("Dummy")

Humanoid.Died:Connect(function()
	
	print("died")
	
	if script.Parent:FindFirstChild("creator") then
		
		if script.Parent.Name == "Level1" then

			game.Players:FindFirstChild(Dummy.creator.Value).PlayerStats.Exp.Value += 160

		elseif script.Parent.Name == "Level10" then

			game.Players:FindFirstChild(Dummy.creator.Value).PlayerStats.Exp.Value += 800

		elseif script.Parent.Name == "Level25" then

			game.Players:FindFirstChild(Dummy.creator.Value).PlayerStats.Exp.Value += 1600

		elseif script.Parent.Name == "Level50" then

			game.Players:FindFirstChild(Dummy.creator.Value).PlayerStats.Exp.Value += 5000
		end

		local player = game.Players:FindFirstChild(Dummy.creator.Value)
		local playerStats = StatsFolder:FindFirstChild(player.Name)

		local QuestsDone = playerStats.QuestsDone

		local CurrentQuest = QuestsDone:FindFirstChild(playerStats.CurrentQuest.Value)

		local QuestData = QuestsFolder:FindFirstChild("Quest"..playerStats.CurrentQuest.Value)

		if QuestData then

			if QuestData.QuestType.Value == "Kill" then

				local DummyLevel = string.match(Dummy.Name,"%d+")

				if QuestData.QuestType.EnemyLevel.Value == 0 or QuestData.QuestType.EnemyLevel.Value == tonumber(DummyLevel) then

					if CurrentQuest.QuantityDone.Value < CurrentQuest.Quantity.Value then

						CurrentQuest.QuantityDone.Value += 1

						player.PlayerGui:WaitForChild("QuestGui").Quest.Text = "Quest: "..QuestData.QuestText.Value.." ("..CurrentQuest.QuantityDone.Value.."/"..CurrentQuest.Quantity.Value..")"
						player.PlayerGui.QuestGui.Reward.Text = "Reward: "..QuestData.Reward.Value.." EXP"

						if CurrentQuest.QuantityDone.Value == CurrentQuest.Quantity.Value then

							CurrentQuest.Value = true

							player.PlayerGui.QuestGui.Reward.Text = "Talk to the NPC!"
						end
					end
				end
			end
		end
	end

	wait(5)

	local DummyClone = DummyStorage:Clone()
	DummyClone.Name = Dummy.Name
	DummyClone.Humanoid.MaxHealth = Humanoid.MaxHealth
	DummyClone.Humanoid.Health = Humanoid.MaxHealth
	DummyClone.Parent = workspace.TrainDummies
	DummyClone:SetPrimaryPartCFrame(Dummy.HumanoidRootPart.CFrame)

	script.Parent:Destroy()
end)

Everything was done on the Server. I tried that and it didn’t work also.

If so, then may I ask how the dummy is being damaged?

I’m not sure if this will work because in studio when I added “WaitForChild()” the died event couldn’t fire. Instead try this maybe it works:

local Humanoid = Dummy.Humanoid

connection = workspace.Stand.Stand["Left Arm"].Touched:Connect(function(hit)
				
				local hum = hit.Parent:FindFirstChild("Humanoid")
				
				if hum then
					
					if hit.Parent.Name ~= owner then
						
						if hit.Parent:FindFirstChild("creator") == nil then
							
							local creator = Instance.new("StringValue")
							creator.Value = owner
							creator.Name = "creator"
							creator.Parent = hit.Parent
							
							game:GetService("Debris"):AddItem(creator,2)
							
						elseif hit.Parent:FindFirstChild("creator") then
							
							hit.Parent.creator.Value = owner
							
							game:GetService("Debris"):AddItem(hit.Parent.creator,2)
						end
						
						if hum.Health > 0 then
							
							if (hum.Health - player.PlayerStats.StandDamage.Value) <= 0 then
								
								hum:TakeDamage(hum.MaxHealth)

							elseif (hum.Health - player.PlayerStats.StandDamage.Value) >= 0 then
								
								hum:TakeDamage(player.PlayerStats.StandDamage.Value)
							end
						end
					end
				end
			end)

This is the script that damages the Dummy. Note: This is not the whole script, but everything related to the dummy is here and this is a server script