AbsolutePosition not matching actual screen posiition?

I’m making a custom hovering system with my mouse for performance optimization, and it seems that the AbsolutePosition doesn’t actually represent its exact position on the screen, specifically in the Y. To demonstrate, I set up a quick script.

while task.wait() do
local frame = script.Parent.Frame
local mouse = game.UserInputService:GetMouseLocation()
frame.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
frame.AbsPosition.Text = "AbsPosition: "… tostring(frame.AbsolutePosition)
frame.Pos.Text = "Position: "… tostring(frame.Position)
frame.MousePosition.Text = "Mouse: "… tostring(mouse)
end

and it shows this:


How can I get around ths?

This is because of GUI Inset. You can remove this offset by enabling the IgnoreGuiInset property in the ScreenGUI.

This doesn’t seem to work in my actual experience, I’m not sure why, but it could be the ancestry of the UI, which involves many different frames as well as layouts and aspectRatioConstraints.
image
Individual elements are added during runtime, but the mismatch still occurs when measuring the absolutePosition and the mouse position.

Then just add an offset to the GUI itself.

What offset you may ask? This offset:

local insetOffset = game:GetService("GuiService"):GetGUIInset().Y
2 Likes

You’ll need to subtract this value on the Y-axis, not add it

I said add an offset. I am referring to it as Insert an offset in your code.

You don’t need to go ahead correcting me all the time… :/

1 Like

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