Frame not following the mouse cursor properly

I am trying to make a Frame follow the mouse cursor, but the frame is too far away from the Mouse Cursor.

This is my code:

local Mouse = game.Players.LocalPlayer:GetMouse()

local hovering = false

local button = script.Parent
local Frame = button.Frame

button.MouseEnter:Connect(function()
	hovering = true
end)

game:GetService("RunService").RenderStepped:Connect(function()
	local X = Mouse.X
	local Y = Mouse.Y
	if Frame then
		if hovering == true then
			Frame.Visible = true
			Frame.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
		else
			Frame.Visible = false
		end
	end
end)

button.MouseLeave:Connect(function()
	hovering = false
end)

Unless your button is positioned at 0,0 on both axes, you need to take into account the button’s position since the frame is located under the button.

It’s still far away, regardless of where the frame is located.

I was talking about the button, not the frame. You need to do something like this:

Frame.Position = UDim2.new(0, Mouse.X - button.Position.X.Offset, 0, Mouse.Y - button.Position.Y.Offset)

did you take in count topbar Y size? if im not wrong they changed it from 36 to 58

a simpler fix for that would be to just enable IgnoreGuiInset property of screengui

		local buttonPosition = button.AbsolutePosition
		local offsetX = X - buttonPosition.X
		local offsetY = Y - buttonPosition.Y

		Frame.Visible = true
		Frame.Position = UDim2.new(0, offsetX, 0, offsetY)
	else
		Frame.Visible = false