Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How do I completely Center a GUI? [closed]

Asked by 10 years ago

This question already has an answer here:

GUI not centering

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

Marked as Duplicate by TofuBytes and BlueTaslem

This question has been asked before, and already has an answer. If those answers do not fully address your question, then please ask a new question here.

Why was this question closed?

2 answers

Log in to vote
1
Answered by
RAYAN1565 691 Moderation Voter
10 years ago

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)}

0
This only works it if they use offset alone. jakedies 315 — 10y
0
Your right. Let me include the general formula for scale and offset RAYAN1565 691 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

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)
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. jakedies 315 — 10y