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

How do I completely Center a GUI?

I have a GUI, but I want to self-center it manually?

2 answers

✓ Accepted answer

Simple... Use the formula:

Simplified Forumula (Offset only)

{0.5, -(width / 2)}, {0.5, -(height / 2)}

General Formula (scale and offset)

{0.5 - (xScaleSize / 2), -(xOffsetSize / 2)}, {0.5 - (yScaleSize / 2), -(yOffsetSize / 2)}

2 comments

0

This only works it if they use offset alone.

0

Your right. Let me include the general formula for scale and offset

If you are using scale (which you should be using, so that the GUI appears the same on all screens), use the following code:

local GUI = Game.StarterGui.ScreenGui.Frame --Change this to the path to your GUI
local x, y = GUI.X.Scale, GUI.Y.Scale
GUI.Position = UDim2.new((1-x)/2, 0, (1-y)/2, 0)

Alternatively, if you are using offset (which could mess the GUI up on smaller screens) then use this:

local GUI = Game.StarterGui.ScreenGui.Frame --Change this to the path to your GUI
local x, y = GUI.X.Offset, GUI.Y.Offset
GUI.Position = UDim2.new(0.5, -x/2, 0.5, -y/2)

1 comment

0

It's not necessarily always a good idea to set the sizes of frames using scale. On smaller screens GUIObjects inside the frame can be squashed. As long as your frame isn't too big it's usually okay to use offset.

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