NPC wont destroy after death?

I made a script where if this NPC dies he will be deleted after 1 second.
miraculously enough the script does not want to function.

Here is the script. It is extremely simple but no one likes a long code.
(It does not show any errors in output)

local Humanoid = script.Parent:FindFirstChild(“Humanoid”)
local NPC = script.Parent
if NPC.Humanoid.Health <= 0 then
wait(3)
NPC:Destroy()
end

it also has nothing to do with the npc, i tried it on another one and it failed to do so too

3 Likes

You did not place your destroy code in a function. Create a new function that waits for a few seconds before destroying the model, and connect that function to Humanoid.Died

local Humanoid : Humanoid = script.Parent:FindFirstChild("Humanoid")
local NPC = script.Parent

Humanoid.Died:Connect(function()
	task.wait(3)
	NPC:Destroy()
end)
7 Likes

Oh, thats strange. The code worked. But the code I used was functioning just fine in my other games. Nonetheless thanks.

3 Likes