Need help to convert offset to scale of an UI relative to another UI

Greetings Everyone.

  1. What do you want to achieve? :
    I’m trying to draw a line between two UI (using a Frame). So far the line script work as I can see.
    This two UI here are the point A and B for drawing the line.

But his position and his scale are not relative to the parent UI, so the line didn’t appear because it is far away from it’s target.

  1. What solutions have you tried so far?:
    I try to use a offset to scale code. This code work perfectly on UI directly parented to a GUI object.
function OffsetToScale(Offset,targetUI)
	local viewPortSize = workspace.CurrentCamera.ViewportSize
	return[1] / viewPortSize.X, 0, Offset[2] / viewPortSize.Y, 0)

So it didn’t work so well on that line because the line his parented to a frame.

And here his the code for drawing a line between two UI.

local VECTOR2_HALF =, 0.5)

function DrawLineFromTwoPoints(lineFrame:Frame , pointA , pointB)

	lineFrame.Size = UDim2.fromOffset(
		math.sqrt((pointA.X - pointB.X) ^ 2 + (pointA.Y - pointB.Y) ^ 2), 2)
	lineFrame.Position = UDim2.fromOffset(
		(pointA.X + pointB.X) / 2, 
		(pointA.Y + pointB.Y) / 2
	lineFrame.Rotation = math.deg(math.atan2((pointA.Y - pointB.Y), (pointA.X - pointB.X)))

	lineFrame.AnchorPoint = VECTOR2_HALF

	return lineFrame

function DrawLineUI(lineFrame:Frame, obj1, obj2)
	-- Get center regardless of anchor point
	local posA = obj1.AbsolutePosition + (obj1.AbsoluteSize * VECTOR2_HALF)
	local posB = obj2.AbsolutePosition + (obj2.AbsoluteSize * VECTOR2_HALF)

	return DrawLineFromTwoPoints(lineFrame, posA, posB)

And here the code I use to call all of the function.

local lineNew = DrawLineUI(lineSkillTree:Clone(),skillFrame,frameLinkedTo.Value)
lineNew.Position = OffsetToScale({lineNew.Position.X.Offset,lineNew.Position.Y.Offset},moverFrame)
lineNew.Size = OffsetToScale({lineNew.Size.X.Offset,lineNew.Size.Y.Offset},moverFrame)
lineNew.Parent = moverFrame.LineStorage

And the actual workspace configuration :

Thanks just after read this mess. And thanks if you help me.

1 Like

What is the size of the Mover frame? Also, you’re dividing the position by your device’s screen size, which means the position is relative to your device, not the frame.,0,2,0) for the Mover frame size,you think that work too with position the offset?

Yes, I think that’s the problem. Try dividing by the absolute size of the Mover frame.

I will try it asap, but for unknow reason (THANKS ROBLOX TO HAVE UPDATE SOMETHING) one of my main script is broken…

If you need help with offset to scale conversion you can use a plugin called “AutoScale - Lite” and for line drawing just use TweenService.

Can’t use Plugin, it’s real time line drawing

Well why not just make a line manually setting the size to UDIM (0,0,1,0) and then tweening the line to the size you want it, if it’s full line then (1,0,1,0)

Because it’s a dynamic ability tree, so make it manually is a problem…

Where do I need to put this division?

function OffsetToScale(Offset,targetUI)
--	local viewPortSize = workspace.CurrentCamera.ViewportSize
	return[1] / targetUI.AbsoluteSize.X, 0, Offset[2] / targetUI.AbsoluteSize.Y, 0)