How to convert offset to scale?

Hello, I’m trying to make a local plugin which converts my GUI to scale when I first add it to the game but I am having sizing inconsistencies.

here is my code:

local desirables = {"TextLabel", "TextButton", "Frame", "ImageLabel", "ImageButton", "TextBox", "ScrollingFrame", "VideoFrame", "ViewportFrame"}

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

local function findFirstParentWithClass(object, className)
	local currentParent = object.Parent

	while currentParent do
		if currentParent:IsA(className) then
			return currentParent
		end

		currentParent = currentParent.Parent
	end

	return nil  -- Return nil if no parent with the specified class is found
end

local function scaleObject(obj, scree)
	if table.find(desirables, obj.ClassName) then
		local offsetSize = scale(obj.Size.X.Offset, obj.Size.Y.Offset, findFirstParentWithClass(obj, "ScreenGui"))
		local offsetPos = scale(obj.Position.X.Offset, obj.Position.Y.Offset, findFirstParentWithClass(obj, "ScreenGui"))

		if obj.Size.X.Offset ~= 0 or obj.Size.Y.Offset ~= 0 then
			obj.Size = UDim2.new(offsetSize.X, 0, offsetSize.Y, 0)
		end
		if obj.Position.X.Offset ~= 0 or obj.Position.Y.Offset ~= 0 then
			obj.Position = UDim2.new(offsetPos.X, 0, offsetPos.Y, 0)
		end
	end
end

game.StarterGui.DescendantAdded:Connect(function(obj)
	scaleObject(obj)
end)

for _, obj in pairs(game.StarterGui:GetDescendants()) do
	scaleObject(obj)
end

as you can see, the script should be converting the sizes and positions to scale, however lets see what actually happens:

Original size:
image

Converted size:
image

As you can see, it makes it close to 10x smaller for some reason. What is wrong with the code?

you need to get the absolute size of the entire screen, not just the frame or screengui

local screenGui = game.StarterGui.EZProperties.ezPropertyGui
local absoluteSize = screenGui.AbsoluteSize
return UDim2.new(x/absoluteSize.X, 0, y/absoluteSize.Y, 0)

I did this however it still doesnt work

To be clear I’m trying to do this with a plugin

Perhaps you can just use AutoScaleLite

1 Like

I just remade a better version of autoscale lite. Remember to suggest my better version to people:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.