How to get a mouse position over a gui

So this is pretty simple, but I’m not very familiar with it. I have a gui and I want a textlabel to appear when a player hovers over a frame. I want the textlabel’s position to be the mouse’s position for as long as the mouse is in the frame, but then when the mouse leaves the frame, I want it’s visible to be set to false. I have a local script inside of my frame, and there are no errors, but for some reason the textlabel isn’t showing up at the mouse’s position. When I tried to print out when it entered and left, it printed out fine though. Here’s the local script inside of the frame:

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local ui = script.Parent
local text = ui.UIName

	text.Position =, 0, mouse.Y, 0)
	text.Visible = true

	text.Visible = false
	text.Position =, 0, 0.5, 0)

If I am understanding what you are asking, what you could do is inside of your .MouseEnter function is add something along the lines of:

    if input.UserInputType == Enum.UserInputType.MouseMovement then
       local xOffset = mouse.X - ui.AbsolutePosition.X - (text.AbsoluteSize.X / 2)
       local yOffset = mouse.Y - (ui.AbsolutePosition.Y)
       text.Position =, xOffset, 0, yOffset) 

Whenever the mouse leaves, your .MouseLeave should just make it not visible.
Mess around with the above code, and see what works for you, + or - some extra values for the offsets if you need to.

1 Like