Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why can't I programmatically read ScreenGui.AbsoluteSize?

I'm trying to get a Gui to have a position based off of the size of a players screen (dont say use scale, because the size of the gui is an offset value not scale), but recently I've noticed that the returned value of script.Parent.AbsoluteSize.X is zero...

Here's my script:

local sizeX = script.Parent.AbsoluteSize.X
local fX = script.Parent.Frame.Size.X.Offset -- value is 125
print(sizeX .. ", " .. sizeX - fX .. " sizeX")
script.Parent.Backing.Position = UDim2.new(0, (sizeX / 2) - (fX / 2), 0, 0)

Output: 0, -125 sizeX

What am I supposed to do now?

1 answer

The issue was that the script was running before the ScreenGui initialized, adding a simple wait() fixed the issue. thanks @cntkillme.

This discussion is preserved as it was. New answers, comments, and votes are closed.