I have a zombie and a script to get rid of it after it has reached zero health. The only problem is that the script doesn't destroy the zombie. Note: The zombie does disappear but it takes somewhere around 10-15 seconds. Here's the script, the humanoid is named "Zombie", and the script is a direct child to the model.
local function die() workspace.CountDown.Value = workspace.CountDown.Value - 1 script.Parent:Destroy() end script.Parent.Zombie.Died:Connect(die)
Usually for npc I do something along the lines of
local zombie = script.Parent local zombieHumanoid = zombie:WaitForChild("Humanoid") while zombieHumanoid.Health > 0 do -- while zombieIsAlive do wait() -- zombie ai stuff etc end -- run code when zombie dies, decrease countdown, respawn etc zombie:Destroy() zombie = nil
This way the npc will interact and do its job, and once it dies it will break from loop and you can handle its death