UI to follow mouse being set above the mouse

My UI currently hovers a few pixels above the actual mouses position

CurrentHover.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)

2 Likes

It looks like the Y property of the mouse takes into account the inset of the top bar. You can subtract 36 from the Y to remove this.

image

(I coded my own really quick, since I was just quickly trying to get it to work here was the code I quickly wrote up)
game:GetService("UserInputService").InputChanged:Connect(function(input, gpe)
	if gpe then return end
	
	if input.UserInputType == Enum.UserInputType.MouseMovement then
		local location = game:GetService("UserInputService"):GetMouseLocation()
		script.Parent.Position = UDim2.new(0, location.X, 0, location.Y - 36)
	end
end)
5 Likes

You could subtract the guis absolute position from the mouses position. It’s how I center my guis that have to do with my mouse mostly.

CurrentHover.Position = UDim2.new(0, Mouse.X - CurrentHover.AbsolutePosition.X, 0, Mouse.Y - CurrentHover.AbsolutePosition.Y)
2 Likes


Seemed to make the gap bigger :confused:

Anchor Point is 0.5,0.5 if that’s of any relevance?

local function MoveHover()
	if not CurrentHover then return end
	
	print(Mouse.X, Mouse.Y)
	CurrentHover.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y - 36)
end

I have IgnoreGuiInset false

And without the -36 theres still a gap

Anchor it 0.5,0.5 and try and use the example I gave if you didn’t already.

1 Like