Converting AbsolutePosition -> UDim2

So im trying to get my tutorial frame (“center”) to hover over a certain button (“frame”)

center.Position = UDim2.new(0, frame.AbsolutePosition.X, 0, frame.AbsolutePosition.Y)

This is the current script which hardly works in itself, as you can see below:

image

FYI the anchor point is 0,0
On top of that this uses Offset. I’d prefer it to use scale so all devices can see it properly on point. Any suggestions? I’ve tried everything :sob:

Do both elements have an anchor point of (0, 0)?

I’m pretty sure you can also do

center.Position = frame.Position

What do you mean by “hover over a certain button”? Are you trying to center the first frame onto the button?

I somehow corrected it, using some info from other related posts i put this together:

center.Position = UDim2.new(0, frame.AbsolutePosition.X, 0, frame.AbsolutePosition.Y) - UDim2.new(0, tutorialHud.AbsolutePosition.X, 0, tutorialHud.AbsolutePosition.Y)

Your solution couldnt have helped sadly as frame is inside of a different gui. and all my uis are scaled on scale not offset, therefore if i set the scale of center to the same as frame. it would be WELL off. Thanks for trying to help though :pray:

So the top left corner of a Gui is the position, so you have to add half of its size to center it:

Center.Position = Udim2.fromOffset(frame.AbsolutePosition.X + Center.AbsoluteSize.X / 2, frame.AbsolutePosition.Y + Center.AbsoluteSize.Y / 2)

You can convert this to scale if you know the screen size, maybe from a screengui or a frame with scale 1, 1?

local scrY = --your Y
local scrX = --your x

Center.Position = Udim2.fromScale(frame.AbsolutePosition.X / srcX + Center.AbsoluteSize.X / srcX / 2, frame.AbsolutePosition.X / srcY + Center.AbsoluteSize.Y / srcY / 2)

I haven’t tested this but hope this helps!

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