How do I position a mouse hover UI?

When I hover my mouse over a player, the center of the UI is not appearing at the mouse’s location, but rather the top left-most corner. In the past, I accounted for the size of this negative space by adding/subtracting values to the offset, but people with different screens would not see the UI centered, but rather moved either too left or too right.

How do I get this UI to be centered at the mouse’s location while also maintaining the correct position for different sized screens?

Current code

local MouseLocation = UserInputService:GetMouseLocation()
HoverInterface.MainFrame.Position = UDim2.fromOffset(MouseLocation.X, MouseLocation.Y)```

Old code (it would center the box only for people with my same screen size. For bigger/smaller screens, it would appear too left or too right).

HoverInterface.MainFrame.Position = UDim2.new(0,X-207,0,Y+20)

set the Frames AnchorPoint properity to 0.5, 0.5

2 Likes