I want to destroy an NPC whenever they die, but I just can't seem to get this to work. No output errors, only print("test") shows in output.

Screenshot of my pathing

Code (Server script parented under Enemy's model named "EnemyDeath")

local humanoid = script.Parent:WaitForChild("Humanoid")
local RunService = game:GetService("RunService")
print("test")

RunService.Heartbeat:Connect(function(deltaTime)
	humanoid.Died:connect(function()
		humanoid.Parent:Destroy()
		print("destroy!")
	end)
end)

6 comments

1

Why do you have the Died event in the Heartbeat event?

0

it was my best attempt at a fix, it still didn't work though

1

Don't see why this wouldn't be working.. Are you dealing damage to the Humanoid from the server or client?

0

Ahhhhh, that's probably it, I was dealing damage from the client

0

yeah it works now, thank you that was really getting on my nerves

1

No problem.