I have a script to despawn an npc after it dies but it does nothing Here is the code:
robot = script.Parent.Robot if robot.Health <= 0 then script.Parent:Destroy() end
BTW, Robot is just humanoid but it is renamed. Also the script is a child of the NPC. & finally, the NPC is a sort of 'zombie' that attacks the player so there are multiple clones of it in the map as well, just in case that messes anything up.
You're not checking every time the humanoids health changes you only check once.
I suggest you use
while true do wait(0.1) -- so it doesn't crash robot = script.Parent.Robot if robot.Health <= 0 then script.Parent:Destroy() end end
a change event may also work, to be honest I've never tried it so I don't know if it will activate every time its health changes but it should.
Also why isn't the despawn script not working is the same as saying why is this script working.
Put your code in a loop so it keeps firing, right now you just have it fire once
If you don't know how to use loops then go to this website:
In this case I would suggest doing this:
While true do wait(0.1) -- The code you have right now goes here end
You shouldnt use less then 0 ( <= 0 ) i would say < 1, Also this isn't looping or in a died function.. so it wouldn't activate