Im getting the center of a frame using Vector2 and then converting it to a Udim2, but what I am trying to position is way off
function self.getCenter(object)
local center = Vector2.new(object.AbsolutePosition.X, object.AbsolutePosition.Y) + object.AbsoluteSize / 2
return UDim2.fromScale(center.X,center.Y)
end
Ok, I think the reason is because you are creating a UDim2 that uses the absolute position as the scale parameter instead of offset.
function getCenter(object)
local center = Vector2.new(object.AbsolutePosition.X, object.AbsolutePosition.Y) + object.AbsoluteSize / 2
return UDim2.fromOffset(center.X,center.Y)
end
The scale value in UDim2 is usually only between values 0 and 1, which are basically the edges of the element(in this case, your screen). The absolute position of a GUI is the position of it according to pixels, counting from the top left of your screen.
Here’s an example: You want to get the center of a 1080p screen.
With scale, you would do UDim2.fromScale(0.5, 0.5), because the number 0.5 is in the middle of 0 and 1.
However, with absolute position, it would be something like UDim2.fromOffset(1920/2, 1080/2), because dividing the screen’s dimensions by 2 gives you the middle.
You can notice the drastic difference between scale and absolute position. And because you used fromScale with absolute position, it won’t work.