TextLabel is offset from mouse

I’m trying to make it so whenever you hover over a textbutton, a textlabel becomes visible and follows your mouse while the mouse is over the textbutton. It’s working, but for some reason it is offset by a lot.

IssueWithMouseUI

Here’s the code:

local mouse = game.Players.LocalPlayer:GetMouse()
local rs = game:GetService("RunService")

local entered = false

script.Parent.MouseEnter:Connect(function()
	entered = true
	script.Parent.InfoFrame.Visible = true
	rs.RenderStepped:Connect(function()
		if entered == true then
			script.Parent.InfoFrame.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
		end
	end)
end)

script.Parent.MouseLeave:Connect(function()
	entered = false
	script.Parent.InfoFrame.Visible = false
end)
1 Like

Make sure the TextTabel is parented directly to the ScreenGui.

3 Likes

Alternatively, here’s a function for setting the AbsolutePosition of a GuiObject, even if it’s parented to something that isn’t at (0, 0):

function setAbsolutePosition(object: GuiObject, absolutePosition: Vector2)
    local relativePosition = absolutePosition - object.Parent.AbsolutePosition
    object.Position = UDim2.new(0, relativePos.X, 0, relativePos.Y)
end