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