Offset Conversion based on Frame size

I wanted to make an offset updater for my dialogue UI, since I cannot use scale as it goes mayham.
So, how do I exactly update the UI from the previous pos/size to the new one when the area it is currently on has been scaled? (let’s say the viewport size on the camera)

I tried using this formula:

newOffset = oldOffset * (newViewportSize / oldViewportSize)
local txt = script.Parent

local txtOldSize = UDim2.new(0, txt.Size.X.Offset, 0, txt.Size.Y.Offset)
local AreaOldSize = Vector2.new(txt.Parent.AbsoluteSize.X, txt.Parent.AbsoluteSize.Y)

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(inp)
	if inp.KeyCode == Enum.KeyCode.X then
		txt.Size = UDim2.new(0, txtOldSize.X.Offset*(txt.Parent.AbsoluteSize.X/AreaOldSize.X), 0, txtOldSize.Y.Offset*(txt.Parent.AbsoluteSize.Y/AreaOldSize.Y))
		txtOldSize = UDim2.new(0, txt.Size.X.Offset, 0, txt.Size.Y.Offset)
		AreaOldSize = Vector2.new(txt.Parent.AbsoluteSize.X, txt.Parent.AbsoluteSize.Y)
	end
end)

but it ended up changing the UI size to just 0,0,0,0
(Or is it just I suck)

2 Likes

If your objective is to change offset to scale and vice versa there’s a plug-in that does this job perfectly

1 Like

Well no, what I meant is not converting offset to scale, but rather just adjusting the scale depending on it’s parent/viewport absolute size.

The reason why is I am using Text Size as textscaled does not produce the desired outcome. So I made a custom one, however it might’ve fixed the text scaled issue, it created another issue where I have to change the offset of the text depending on its parent absolute size