Humanoid.Died event not firing

My goal is that the humanoid.died event runs, and then with a function it deletes the npc.

The Humanoid.Died event simply does not fire.

I have tried using HealthChanged too, or checking continuously for the health but for some reason those dont work as well.

This is in a server script, inside the npc model. This must be a server script, and i don’t want anything on the client side, for security reasons.

1 Like

What does your code look like?

local enemy = script.Parent
local waypoints = workspace.Waypoints

for waypoint = 1, #waypoints:GetChildren() - 2 do
    repeat enemy.Humanoid:MoveTo(waypoints["Waypoint" .. tostring(waypoint)].Position); until enemy.Humanoid.MoveToFinished:Wait()
end

enemy.Humanoid:MoveTo(waypoints.Endpoint.Position)

enemy.Humanoid.Touched:Connect(function(touchingPart)
    if touchingPart.Name == "Endpoint" then
        enemy:Destroy()
    end
end)

enemy.Humanoid.Died:Connect(function()
    enemy:Destroy()
end)

the top part of the code is just me moving the npc, as this is a tower defense game, but the last 3 lines are what im trying to use to destroy the npc upon death.

This is because the event is being created after the enemy has moved through all the waypoints, you can fix it by moving them in front like this:

local enemy = script.Parent
local waypoints = workspace.Waypoints

enemy.Humanoid.Touched:Connect(function(touchingPart)
    if touchingPart.Name == "Endpoint" then
        enemy:Destroy()
    end
end)

enemy.Humanoid.Died:Connect(function()
    enemy:Destroy()
end)

for waypoint = 1, #waypoints:GetChildren() - 2 do
    repeat enemy.Humanoid:MoveTo(waypoints["Waypoint" .. tostring(waypoint)].Position); until enemy.Humanoid.MoveToFinished:Wait()
end

enemy.Humanoid:MoveTo(waypoints.Endpoint.Position)

Thank you so much, it works! Ill keep this stuff in mind for the future.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.