Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why isn't the despawn script for my NPC not working?

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.

3 answers

✓ Accepted answer

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.

2 comments

0

K thanks for the answer, & yeah sorry I didn't realise that I wrote the title like that.

0

No problem :) title just confused me while scrolling past so thought I'd let you know

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

This discussion is preserved as it was. New answers, comments, and votes are closed.