im trying to set the absolute position of the blue square to the red square but it doesn’t work
for screen gui, i clicked on ignore gui inset
and also for the 2 squares they both have an anchor point of (0.5, 0.5)
local gui = script.Parent
local Red = gui.Red
local Blue = gui.Blue
local AbsPos = Red.AbsolutePosition
Blue.Position = UDim2.new(0, AbsPos.X, 0, AbsPos.Y)
print(Red.AbsolutePosition)
print(Blue.AbsolutePosition)
ok here’s the solution if you want anchor point to be .5,.5 and also account for ignore gui inset
I added a marker to check if its correct
also setting ui position, it always rounds to the nearest whole number, so it doesn’t perfectly aligns
local GuiService = game:GetService("GuiService")
local gui = script.Parent
local marker = gui.Marker
local Red = gui.Red -- Replace "ParentObject" with the name of your parent object
local Blue = Red.Blue -- Replace "ChildObject" with the name of your child object
Blue.AnchorPoint = Vector2.new(0.5, 0.5)
local inset1, inset2 = GuiService:GetGuiInset()
local insetOffset = inset1 - inset2
local topLeftPosition = Blue.AbsolutePosition + insetOffset
local size = Blue.AbsoluteSize
local centerPosition = topLeftPosition + size / 2
print("Center position of child object: " .. tostring(centerPosition))
marker.Position = UDim2.new(0, centerPosition.X, 0, centerPosition.Y)