Humanoid.Died not firing in specific models

I added a tag called Enemy to all my NPCs and I’m working with Collection Service.

Function Explanation

When the game starts, the collection service starts setting all NPCs’ name, level, health and color skin. And when they die, the Humanoid.Died event fires and after their own respawn time they are suppose to destroy the old model and bring the cloned model before dying to NPCs folder.

The Issue

This event works with 2 type of humans; Archers and Armed Villagers. But I noticed something wrong with all models called Villager. There are 3 extra villager models which they are called Strong Villager, Heavy Villager and Brutal Villager, these three work as well as the Archers and Armed Villagers, however, this doesn’t happen with the Villagers.

The Script

local collection = game:GetService("CollectionService")

local skins = {
	[1] = Color3.fromRGB(255, 230, 221),
	[2] = Color3.fromRGB(253, 212, 184),
	[3] = Color3.fromRGB(125, 104, 91),
	[4] = Color3.fromRGB(136, 70, 61)
}

local function Respawn(npc)
	local newNpc = npc:Clone()
	local config = npc.Config

	local gui = npc.HealthGui
	local frame = gui.Health
	local bar = frame.Bar
	local amount = frame.Health

	local humanoid = npc.Humanoid
	local bodyColors = npc["Body Colors"]
	local random = skins[math.random(1, #skins)]
	
	bodyColors.HeadColor3 = random
	bodyColors.LeftArmColor3 = random
	bodyColors.RightArmColor3 = random
	bodyColors.LeftLegColor3 = random
	bodyColors.RightLegColor3 = random
	bodyColors.TorsoColor3 = random
	
	gui.Adornee = npc.HumanoidRootPart
	gui.Enabled = true
	gui.NPCName.Text = npc.Name
	gui.Level.Text = "Level " .. config.Level.Value
	amount.Text = humanoid.Health .. " / " .. humanoid.MaxHealth

	humanoid.Died:Connect(function()
		print("Npc died")
		wait(config.Respawn.Value)
		print("Npc respawned")
		newNpc.Parent = workspace.NPCs
		npc:Destroy()
	end)
	
	humanoid.HealthChanged:Connect(function(hp)
		if hp <= 0 then
			amount.Text = "0 / " .. humanoid.MaxHealth
			bar.Size = UDim2.new(0, 0, 1, 0)
		else
			amount.Text = math.round(hp) .. " / " .. humanoid.MaxHealth
			bar.Size = UDim2.new(math.round(hp)/humanoid.MaxHealth, 0, 1, 0)
		end
		bar.BackgroundColor3 = Color3.new(0.807843, 0.176471, 0.176471):Lerp(Color3.new(0.266667, 0.835294, 0.227451), hp / humanoid.MaxHealth)
	end)
end

collection:GetInstanceAddedSignal("Enemy"):Connect(function(npc)
	Respawn(npc)
end)

for _, npc in pairs(collection:GetTagged("Enemy")) do
	Respawn(npc)
end

Attempts

As my first attempt, I removed all Villager models but I kept only one in the map, this didn’t work.

I printed at the beginning of the function print("added .. npc.Name") and the output included the Villagers, but this didn’t mean that Humanoid.Died event could fire.

Honestly I have no clue what is the mistake, I was running out of attempts so I went to check if Villagers had their tags, and they do.

All these lines in the script work perfectly, the issue is the Humanoid.Died not firing with specifically all models called Villager.

EDIT: I discovered something weird, I increased a villager’s max health from 100 to 150, somehow the Humanoid.Died worked. But it’s strange why with 100 health it doesn’t work, the damage I inflict on them is much much higher than their health, around 100k damage. Does that have anything to do with the event not working?

1 Like

Not that this is a solution for something weird happening with the :Died, but have you checked to see if even the HealthChanged is firing?

Yea HealthChanged is firing, I added the

if hp <= 0 then
			amount.Text = "0 / " .. humanoid.MaxHealth
			bar.Size = UDim2.new(0, 0, 1, 0)

because for some reason the health crossed the number 0 to -6000, number that means my damage, and the health bar was not suppose to get out of the bar frame.

HealthChanged is doing well because the npc’s health update, including the Villagers’ health