I want a GUI to be in the middle of the bottom screen but when i join on my game with my alt on another computer the GUI seems to be way far to the left than the middle, but on my other laptop the GUI is perfect. Any idea how to fix this?
How to i fit a GUI on everyone's screen at the same position?
2 answers
repeat wait() until workspace.CurrentCamera.ViewportSize ~= Vector2.new()
function toScale(instance)
for _,v in pairs(instance:GetChildren()) do
if v:IsA("GuiObject") then
local size = v.Parent:IsA("GuiObject") and v.Parent.AbsoluteSize or workspace.CurrentCamera.ViewportSize
local pos = v.AbsolutePosition - (v.Parent:IsA("GuiObject") and v.Parent.AbsolutePosition or Vector2.new())
v.Size = UDim2.new(v.AbsoluteSize.X/size.X, 0 , v.AbsoluteSize.Y/size.Y)
v.Position = UDim2.new(pos.X/size.X, 0 , pos.Y/size.Y)
end
toScale(v)
end
return
end
toScale(game.StarterGui)
20,000,000
2 comments
INDENT YOUR CODE!!!!!!!!!!!!!!!!!!!!!!!!!!
....
Instead of using Offset, use scale!
If you look at the Position of a Gui, it probably looks something like this:
{0, 200},{0, 500} -- Attempted middle of the screen
The solution then is to use the Scale (the 0's in the first example)
{0.5, 0},{0.5, 0} -- The middle of the screen
One thing you should note though, is the above solution sets the top left of the Gui Element in the middle of the screen. If you want a Gui to be centered, you will need to use the following:
-- Position = {0.5, 0},{0.5, 0} This is the middle of the screen.
-- Using this will make the top left of a Gui in the middle of the screen
To center a Gui, we will use the following
Position = {.5, -Gui_Element.Size.X.Offset / 2, .5, -Gui_Element.Size.Y.Offset / 2}
Note that you do not need to script this. In fact, I don't recommend scripting it. In Studio, in the Properties box, follow the same format and do the math yourself by diving the x and y values of Size by 2 and then making them negative.
This discussion is preserved as it was. New answers, comments, and votes are closed.

1 comment
So what im asking is there a possible way to retrieve the screen resolution of the user's monitor?