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

Why can't I programmatically read ScreenGui.AbsoluteSize?

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago

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

Ad

Answer this question