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

Co-ordinates to center a GUI?

Asked by 9 years ago

Is there a script to center a GUI no matter what resolution a PC has? I've been looking for one, i've even attempted to make a script but sadly my scripting skill level stinks. ( I'm currently learning how to script on the ROBLOX wiki )

2 answers

Log in to vote
2
Answered by 9 years ago

Inside a LocalScript in the PlayerGui or Backpack

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local Xcenter, Ycenter = (mouse.ViewSizeX / 2), (mouse.ViewSizeY / 2)
print(Xcenter, Ycenter)

If you want to position the Gui in the center here the code:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()

local screenGui = script.Parent
local Frame = screenGui.Frame

local XcenterFrame, YcenterFrame = (Frame.Size.Offset.X / 2), (Frame.Size.Offset.Y / 2)
local Xcenter, Ycenter = (mouse.ViewSizeX / 2), (mouse.ViewSizeY / 2)
local finalXPos, finalYPos = (Xcenter - XcenterFrame), (Ycenter - YcenterFrame)

Frame.Position = UDim2.new(0, finalXPos, 0, finalYPos)
0
Thx for the help! :D secretboy6 68 — 9y
0
p = screenGui p.Position = UDim2.new(0.5,-p.AbsoluteSize.X/2,0.5,-p.AbsoluteSize.Y/2) systematicaddict 295 — 9y
0
You're welcome ! XToonLinkX123 580 — 9y
Ad
Log in to vote
1
Answered by
KoreanBBQ 301 Moderation Voter
9 years ago

Just use the Scale part of a UDim2.

And make the position:

gui.Position=UDim2.new(.5-gui.Size.X.Scale/2,0,.5-gui.Size.Y.Scale/2,0)

Answer this question