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

Why won't this loop break?

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

✓ Accepted answer

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.

1 comment

0

Thanks, worked like a charm.

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

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