How do I convert offset to scale?

I know this sounds very simple but in truth, I’ve tried to figure it out, I looked at posts and what not but none of them worked, so how do I do it? how do I convert offset to scale of a GUI object(E.g. A gui Frame)

2 Likes

This should help

local viewportSize = workspace.Camera.ViewportSize

local function offsetToScale(offset: UDim2): UDim2
	return UDim2.fromScale(
		offset.X.Offset / viewportSize.X,
		offset.Y.Offset / viewportSize.Y
	)
end

-- A more accurate one which uses `AbsoluteSize`:
local function scaleGuiSize(gui: GuiObject): UDim2
	return UDim2.fromScale(
		gui.AbsoluteSize.X / viewportSize.X, 
		gui.AbsoluteSize.Y / viewportSize.Y
	)
end

This was answered in the past:

There is a property in ScreenGui, called AbsoluteSize. Which gives you the size of the screen.(In offset)

The origin is at the top left of the screen.(0,0,0,0) and the bottom-right is equivalent to the size of your screen.(0,1920,0,1080) Take 1920X1080 resolution for example.

Basically Scale stands for the ratio of ScreenSize and the Offset.

For example, if you put 0.5 in scale and that means the half of the ScreenSize. 1 is to cover the entire screen size.

Think this way, AbsoluteSize X Scale will be the offset. And do what you usually do in the math class.

With this idea:

(AbsoluteSize X Scale = Offset) divide both side with AbsoluteSize will become

(AbsoluteSizeX Scale = Offset /AbsoluteSize)

So if you want to convert offset to scale. Use the this formula (Scale = Offset/AbsoluteSize).

2 Likes

Yes I could use this but I want to do it with code, thanks though

1 Like

so we divide xOffset by AbsoluteSize? and not AbsoluteSize.X?

1 Like