Convert AbsolutePosition to Position

The title basically says what im trying to do
this is what i tried

function convertAbslouteToScale(frame)
	local containerAbsolute = frame.Parent.AbsolutePosition
	local frameAbsolute = frame.AbsolutePosition
	
	return UDim2.fromScale(containerAbsolute.X / frameAbsolute.X, containerAbsolute.Y / frameAbsolute.Y)
end
	print(frame.Position)
	print(convertAbslouteToScale(frame))
	

image
this is the result i get

2 Likes

You seem to be misunderstanding how the Scale of a Position works. Just scroll down if you want to see the solution, but to explain, the scale values of Frame.Position is the relative AbsolutePosition of the Frame divided by the AbsoluteSize of its container. If you were to use Offset to dictate your Frame’s position, the Frame.Position would be the Frame’s relative AbsolutePosition.

To calculate the relative AbsolutePosition of the Frame, simply subtract the AbsolutePosition of its container from Frame.AbsolutePosition.

After, all you need to do is divide the relative AbsolutePosition of the frame by its container’s AbsoluteSize.

Code:

function convertAbsoluteToScale(frame)
	local container = frame.Parent
	
	local containerAbsPos = container.AbsolutePosition
	local containerAbsSize = container.AbsoluteSize
	
	local frameAbsPos = frame.AbsolutePosition
	
	local frameRelativePos = frameAbsPos - containerAbsPos

	return UDim2.fromScale(frameRelativePos.X / containerAbsSize.X, frameRelativePos.Y / containerAbsSize.Y)
end
6 Likes

Thank you so much! :heart::heart::heart:

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