Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago
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

0
Line 1: `Health = script.Parent.Humanoid` Line 6 `if Health.Health > 0 then` TheeDeathCaster 2368 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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 &lt; = so the code will run only if the health is below or equal to 0.

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. OmegaNoobBones 4 — 6y
0
script.Parent.Head:Destroy() Axceed_Xlr 380 — 6y
Ad

Answer this question