Convert offset to scale

I’ve been looking through different posts but couldn’t get a straight forward answer. I want a function that would take x and y value as an input (gui object offset sizes) and return me a object with those values switched into scale instead of offset.

Also I don’t use a plugin because the object in instanced by a script. And during this instancing process I want to set the size of it to the given x and y but as scale.

You’ll just want to divide the offset size by the actual bounds of the screen:

Scale = offsetInput / screenSize

Do that for X and Y and you’ll be able to convert whatever you want easily. However, the screen size must be defined so scale can be calculated and can scale properly with everything else as well


Thank you! Do you have an idea of how would I get the screenSize? Is it from the camera property maybe?

I tried doing something like this:

local vS = workspace.Camera.ViewportSize
return, 0, y/vS.Y, 0)

inputs were x=300, y=200
but it just returned me, 0, 200, 0)

After some searches and help of Avxnt I got it.
Here is the function I made:

local function scale(x, y, screenGui)
	local absoluteSize = screenGui.AbsoluteSize
	return, 0, y/absoluteSize.Y, 0)

What about Offset to Scale? I’m sure that will also come in handy.

1 Like