How you can convert scale to offset & offset to scale

I was recently looking for ways to convert Scale to Offset & Offset to Scale. I feel like the method I found was the best and most simple method.

local function OffsetToScale(Vector2 offset, Vector2 screenSize)
    return offset / screenSize
end
local function ScaletoOffset(Vector2 scale, Vector2 screenSize)
    return scale * screenSize
end

Also if you don’t know how to find the players screen resolution / screen size, here is one way you can find it.

local screenSize = workspace.CurrentCamera.ViewportSize
1 Like

You could just use a plugin such as:

Most people like to learn how to do these things by themselves.

1 Like

You need to consider the parent of the object’s AbsoluteSize you’re converting the values on:

function OffsetToScale(offset: Vector2, object: GuiObject): Vector2
    return offset / object.Parent.AbsoluteSize
end

function ScaleToOffset(scale: Vector2, object: GuiObject): Vector2
    return scale * object.Parent.AbsoluteSize
end

If you’re working with LayerContainer objects, like ScreenGuis, as the parent of the object you’re converting the values on, then these do inherit the AbsoluteSize property from the GuiBase2d class. For a ScreenGui specifically, the AbsoluteSize of it is your viewport’s size

ScreenGui.AbsoluteSize

Will fetch the screen resolution of the native device also.