Certain if statement not working for me

Im not very good at if statements so basically i have a npc called “crook”
and when it dies or its humanoid health status reaches 0, i want a certain part called “testpart”
to be destroyed.
However once it reaches 0, the part stays there so im guessing im doing something wrong with the end statement or somewhere inside… Can someone help me out here?
if game.Workspace.crook.Humanoid.Health == 0 then game.Workspace.testpart:Destroy()


Is the testpart a child of the npc? Since you are calling for Workspace.testpart to be destroyed and it isn’t I’d look into where the testpart is.
You could also put a print(“testpart destroyed”) statement after the if…Health == 0 to check to see if the script is getting that far.

no its not a child of the npc and ok ill try that out

Im pretty sure im just wording it strangely or the end needs to be like end)

Is this your entire script?
It looks to me like you have only an if statement; so even if it works, it’s only checking your condition once at the beginning of the game, and never again. Luckily, we can use what’s called an event to have code run when a certain thing happens. In this case, you want to destroy the part when the crook dies. We can use the Humanoid.Died event for this:

workspace.crook.Humanoid.Died:Connect(function() --This is one way to connect a function to an event

Oh thats so cool I didnt know a died event even existed!

1 Like