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

Why won't this loop break?

Asked by 8 years ago

I'm trying to make a Gui where when you're underwater you have a air meter that slowly goes down. Right now I'm just trying to make a working status bar, but it's not working. When the air value gets to 0 it's supposed to stop but it keeps going, making the Gui go out of it's frame. (Like negative numbers)

air = 1

while wait(.1) do
    air = air - 0.01
    script.Parent.Size = UDim2.new(air , 0 , 1 , 0)
    if air == 0 then break
    end
end

Also, this script is located like this: ScreenGui > Frame > Text Label > Script

2 answers

Log in to vote
1
Answered by 8 years ago

Instead of using if air == 0, use if air <= 0. This way, in case the number system accidentally skips over 0, it will still run if the value is below 0. I've noticed in some of my scripts like this one that when it is changing the numbers it somehow changes the value to something like 12.999999999 or something, so in this case it starts skipping integers, like 0.

0
Thanks, worked like a charm. ghostblocks 74 — 8y
Ad
Log in to vote
-2
Answered by 8 years ago

im very basic at scripting but heres my shot lol..

air = **1**

while wait(.1) do
    air = air **- 0.01**

1 - .01 does not equal 0

Answer this question