Consistent way to convert offset to scale

Currently having a problem with covering my frame’s offset to scale during runtime

The frame is contained within the main grid frame in the following hierarchy

CurrentCode:

Object.Position = UDim2.fromScale(Object.AbsolutePosition.X  / Camera.ViewportSize.X, Object.AbsolutePosition.Y / Camera.ViewportSize.Y)

Hello! I see you’ve run into an issue I’ve had before… somehow I haven’t really fixed it myself until now!

So Scale is represented as a percentage of the total ViewportSize, so to simply convert, we’d have to do some basic division:

local ViewportSize = workspace.CurrentCamera.ViewportSize

local Gui1 = -- path to the gui
local Gui2 = -- path to the gui

local function ConvertScaleToOffset(Offset)
      local X = Offset.X.Offset
      local Y = Offset.Y.Offset
      
      local TotalX = ViewportSize.X
      local TotalY = ViewportSize.Y     
 
      local FinalX = X / TotalX -- Gets percentage of the screen based on X component.
      local FinalY = Y / TotalY -- Gets percentage of the screen based on Y component.
      
      return UDim2.new(FinalX,0,FinalY,0)
end

This code here should essentially be self explanatory, to convert scale back to offset, you simply multiply the scale by the original component X or Y of the ViewportSize.

That’s one less person who has to struggle! PS: MAKE SURE TO TURN ON IgnoreGuiInset on your ScreenGui! :wink: