Converting offset to scale

I want to use a script to convert the offset values on my inventory slots which are frames to scale and change the positions of those slots to those new values. The issue is that it doesn’t work at all. I have 35 slots in total and 6 are in the correct spots. the rest are outside of the main frame entirely.
I’ve tried to use the formula scale = offset/AbsoluteSize and searched around on the devforum but nothing has worked so far.

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(plr)
	local inv = plr.PlayerGui:WaitForChild("Inventory")
	local insideFrame = inv.Main:WaitForChild("InsideFrame")
	local slots = insideFrame:WaitForChild("Slots")
	
	local parentSize = insideFrame.AbsoluteSize

	for _, slot in ipairs(slots:GetChildren()) do
		if slot:IsA("Frame") then
			local position = slot.Position

			local scaleX = position.X.Scale + (position.X.Offset / parentSize.X)
			local scaleY = position.Y.Scale + (position.Y.Offset / parentSize.Y)

			slot.Position = UDim2.new(scaleX, 0, scaleY, 0)
		end
	end
end)

There is a plugin called AutoScale Lite, I think you could get that still

I have that plugin. I was originally planning to use it but it didnt work. I dont know why.

I’ve also encountered issues with AutoScale. Try something like this;

-- Assuming you have a UI element called "uiElement" that you want to convert offset to scale
local uiElement = -- Reference to your UI element, e.g., script.Parent.UIElement

-- Function to convert offset to scale
local function offsetToScale(offset, parentSize)
    return offset / parentSize
end

-- Example usage:
local offset = 50 -- Replace with your offset value
local parentSize = uiElement.Parent.AbsoluteSize.Y -- Replace with your parent element's size

local scale = offsetToScale(offset, parentSize)
print("Scale:", scale)

Edit: I assume you want it applied automatically, try this;

-- Assuming you have a UI element called "uiElement" that you want to convert offset to scale
local uiElement = -- Reference to your UI element, e.g., script.Parent.UIElement

-- Function to convert offset to scale
local function offsetToScale(offset, parentSize)
    return offset / parentSize
end

-- Example usage:
local offset = 0 -- Change offset to 0
local parentSize = uiElement.Parent.AbsoluteSize.Y -- Replace with your parent element's size

local scale = offsetToScale(offset, parentSize)
print("Scale:", scale)

-- Apply the scale to the UI element
uiElement.Scale = Vector2.new(scale, scale)