I have a script to despawn an npc after it dies but it does nothing Here is the code:
1 | robot = script.Parent.Robot |
2 |
3 | if robot.Health < = 0 then |
4 | script.Parent:Destroy() |
5 | 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
1 | while true do |
2 | wait( 0.1 ) -- so it doesn't crash |
3 | robot = script.Parent.Robot |
4 | if robot.Health < = 0 then |
5 | script.Parent:Destroy() |
6 | end |
7 | 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:
1 | While true do |
2 | wait( 0.1 ) |
3 | -- The code you have right now goes here |
4 | 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