While Udim2 [Need help]

Hey there!

So i have this line of code which for some reason doesn’t work:

while script.Parent.Size ~= UDim2.new(1,0,0,0) do

I want for the while loop to exit when the Y axis size is 0 (ImageLabel).
In the while loop the Y axis size increases by 0.01 every 0.001 seconds:

script.Parent.Size = script.Parent.Size - UDim2.new(0,0,0.01,0)

For some reason when the size of the ImageLabel is (1,0,0,0), you don’t exit out of the while loop

Any help is appreciated!

There could be many reasons for this. The main one is likely due to floating point imprecision. It could be 1.01, or even 99.9999, you never know.

Can’t you use TweenService and then use the Tween.Completed event?

1 Like

Hm, my first thought was to use a while loop , because i need to change the size and the position, but i guess ill tween the size and position at the same time (if that’s possible).

1 Like

GuiObjects come with a :TweenSizeAndPosition method. Its last argument is a callback function that will be called with argument Enum.TweenState of either Canceled or Completed.

2 Likes

Yeah, thats literally the exact name of a built in function for tweening UI objects.
There’s three:

:TweenSize
:TweenPosition
:TweenSizeAndPosition
1 Like

Try watch this documentations
https://developer.roblox.com/en-us/api-reference/datatype/UDim2
Maybe it should help you

1 Like

Oh right. Thanks for the help.