Getting the center of a UI

function GetCorner(sz, pos, anch)
 pos = typeof(pos) == 'UDim2' and Vector2.new(pos.X.Offset, pos.Y.Offset) or pos
 anch = anch or Vector2.new(0,0)
 return pos+(sz*anch)
end

while wait() do
 local obj = script.Parent
 local Corner = GetCorner(obj.AbsoluteSize, obj.Position, obj.AnchorPoint)
 local Center = Corner+(obj.AbsoluteSize/2)
 script.Parent.Parent.Center.Position = UDim2.fromOffset(Center.X,Center.Y)
end

Code

So as the title says I need to get the center point of a UI but the script dosent even work idk why now I took it from devfroum so it should work but na it dosent so can someone help me in it?

Just get the parents AbsoluteSize property and divide it by 2, it will return a UDim2 of the middle in offset

no i need it in like lets say the thing i want to position is not the child of the gui and yea like that idk what its called

Ok, lets change the question a bit, why do you want to get the middle of a ui?

to fix my script thats why also why do u ask that and dont change the question or u dont even know the answer

Try this and tell me if it works, it returns a Vector2 of the location of the middle of the UI

local function getmidpoint(gui)
	return Vector2.new(gui.AbsoluteSize.X/2,gui.AbsoluteSize.Y/2)
end

i want the position globally not locally

For like a surface gui on a part or something?

no screen gui

Have you tried using AbsolutePosition?

1 Like

before u messaged no after u message but before seeing it yes i did and my problem is solved not by you

 local middle = frame.AbsolutePosition+(frame.AbsoluteSize/2)
 point.Position = UDim2.fromOffset(middle.X,middle.Y)