The pixel part of udim2 requires integer instead of numbers. How do I convert a variable that takes form as a number to the nearest integer?
UDim2 (in UI properties like Size and Position) automatically rounds the offset values into integers. But if you still need to round them manually, use math.floor()/math.ceil().
Weird thing is that when I insert the variable, it doesn’t work. So I thought it was because of the number issue. By the way, my variable is AbsoluteSize.X I tried printing it in the logs and it printed out a number, just didn’t work when I inserted it into Udim2
You can round to the nearest number by using
math.floor(num + 0.5)
I’m not sure I understand how you’re using the data, I feel like you may be writing it incorrectly. How are you setting up the UDim2 variable?
Are you getting any errors in output?
Can you print the newly create Udim2? (sorry wrong tag)
No. And this is the hierarchy
Have you confirmed that AbsX*1.78 > AbsY when you’re testing it? I’m not sure what could be wrong at this point (at least nothing caused by the code), it could just be something to do with the UI itself.
Yes I tested it it and it works if I replace AbsX with a number
What value is AbsX and what does bg1.Size get set to?
AbsX was 1050. and bg1.Size was originally (1,0,1,0)
Then AbsX*1.78 > AbsY
must be false, otherwise the OffsetY should be 500 and the ScaleX/ScaleY 0.
As I already said. I substituted AbsX with actual numbers and it worked. So the line of code did indeed run.
If you do .Size = UDim2.new(1, 2, 3, 4)
and .Size doesn’t end up even resembling that in the slightest, I doubt it actually ran.
I did that already and it ran. I knew the line ran, because I set a breakpoint there. When it originally didn’t work, I checked the playergui and the size was changed to (0,0,0,0)
Are you doing it all from the serverscript? Including placing the ScreenGui into the PlayerGui? If so, try using a localscript, and putting it in ReplicatedFirst or just StarterGui.
Since it runs with actual integers inserted, that means it has something to do with the variable itself. I highly doubt using a local script will make a difference considering the fact that it doesn’t require local script to get the AbsoluteSize of a gui
It most likely has something to do with the variable itself, but GUIs should be handled by the client either way, so it’s worth a try.