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

How to perfectly position a GUI on all screens?

I am currently researching how to do it but with no luck, I am trying to have the whole screen be a gui with little buttons and such around it, this is what I am inserting to my TextButton's and Text labels.

script.Parent.Position = UDim2.new(0, 0 - (script.Parent.Size.X.Offset / 2), 0, 0 - (script.Parent.Size.Y.Offset / 2))

To help position it right, but even so it still shows up different on different screens, please help!

3 answers

✓ Accepted answer

#What's the problem You use Offset, that only changes the amount of Pixels it moves. Scale moves the gui and changes the gui's shape based on screen size.


#Final Product

script.Parent.Position = UDim2.new(0-(script.Parent.Size.X.Scale/2), 0-(script.Parent.Size.Y.Offset/2),0)
--I don't understand what your script is for, just remember to use scale if you want to compensate for screen size


Hope it helps!

1 comment

0

Thanks!

The simple answer is to use scale rather than offset. There are in fact very few cases where you should use offset.

Scale (the first number) is really simple to understand: a value of 0 represents the left of the screen on the X axis or the top of the screen on the Y. A value of 1 represents the right of the screen on the X axis or the bottom of the screen on the Y axis. Therefore, a value of 0.5 is halfway across screen, for example.

Scale will always take up the same portion of the screen no matter what size the screen is, making it preferred over offset.

3 comments

0

You need to say, that if you do a scale of 0.5, then the gui wouldn't be directly in the center, but instead the left side would be. If you were to do UDim2.new(0.5,0,0.5,0) then the top left corner would be centered.

0

You'd need to use this equation: UDim2.new(0.5,-Gui.Position.X.Offset/2,0.5,-Gui.Position.Y.Offset/2)

0

Thanks for the quick answer! :)

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