Script that makes UI Right into the middle

Hello! Is there a script that can make UI right into the middle, instead of anchoring because sometimes Anchoring does not put it right it into the middle, specially when you scale your tab. How can I make it right into the middle with a script. Like when you rescale your tab, no matter what it’ll be right in the middle, even depending on the type of the screen.

Any help will be appreciated! Thanks.

local UI = -- Define here

UI.AnchorPoint = Vector2.new(0.5,0.5)
UI.Position = Udim2.fromScale(0.5,0.5) 

I believe this would work. However you should do this manually.

Is that a example script, or is that the exact script that would work?

Make sure to define where your UI is and it should work.

Edit: Just to test, create a local Script and put into the frame you are trying to centre and put this code into that.

local UI = script.Parent

UI.AnchorPoint = Vector2.new(0.5,0.5)
UI.Position = Udim2.fromScale(0.5,0.5) 

local UI = StarterGui.UpgradeGUI.Frame

	UI.AnchorPoint = Vector2.new(0.5,0.5)
UI.Position = Udim2.fromScale(0.5,0.5)

Like that?

May I ask where is the script? Also does it have to be done via script?

The reason why I asked is become sometimes when you rescale your tab, everything just goes lower, if you know what I mean? It’s kinda confusing. I don’t really need a script, but I was just wondering if that would fix it.

Go to the frame properties and paste this into AnchorPoint: 0.5, 0.5 and for Position: 0.5,0,0.5,0. I am also hoping that your Size is on scale and not offset.

It’s ofcouse on scale not on offset haha (including position), and if I do 0.5,0.5 for anchor, do I also have to do that for position?

0.5, 0.5 AnchorPoint makes the Anchor Centre on the Gui. 0.5,0,0.5,0 Position just positions the frame in the middle of your screen.

1 Like