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

Why wont this script thats meant to print when the health is zero work?

Health = script.Parent.Humanoid.Health
Head = script.parent.Head
Eye1 = script.Parent.Eye1
Eye2 = script.parent.Eye2

if Health > 0
then print("Hello world!")
end

Here is the model of the slug that I'm trying to make the script work for, https://www.roblox.com/library/1483332684/Evil-Slug

1 comment

0

Line 1: Health = script.Parent.Humanoid Line 6 if Health.Health > 0 then

1 answer

✓ Accepted answer

Your script probably only runs once, that’s why. You can use a loop or function to fix this. Here’s some examples :

Loop :

Health = script.Parent.Humanoid.Health
Head = script.parent.Head
Eye1 = script.Parent.Eye1
Eye2 = script.parent.Eye2

while wait() do

if Health <= 0 then
print("Hello world!")
end

end

Loops will constantly run the code that is in the loop, but that also means it will not run any code under it until the loop ends/breaks.

Function :

Humanoid = script.Parent.Humanoid
Head = script.parent.Head
Eye1 = script.Parent.Eye1
Eye2 = script.parent.Eye2

Humanoid:GetPropertyChangedSignal(“Health”):Connect(function()
if Humanoid.Health <= 0
then print("Hello world!")
end

I prefer functions more as code can still run through the functions instead of stalling at it. This function will run once the health property in the humanoid changes.

Hope this helped!

Also why are you using > ? That makes the conditional statement run only if the health is greater than 0 (Ex: 1, 3, 100, etc.). I changed it to < = so the code will run only if the health is below or equal to 0.

2 comments

0

This works, But could you also make it so that when the health is 0 that it deletes all of the parts from the slug? I have no idea how to delete parts with scripts.

0

script.Parent.Head:Destroy()

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