Help with creating a hover text effect with GUI

You can write your topic however you want, but you need to answer these questions:
Currently, I’m trying to make a kinda text hover effect, so when you hover over a textbutton a textlabel appears that follows your mouse.

But, whenever I try and create the Y position of the textlabel just isnt correct.

I’ve tried looking on google at the devforum, but found nothing.

Heres my code that I have currently:

local TextButton = script.Parent.Parent
local TextLabel = script.Parent
local Mouse = game.Players.LocalPlayer:GetMouse()

----| Functions |----
function UpdatePosition()
	TextLabel.Visible = true
	TextLabel.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
end

function Remove()
	TextLabel.Visible = false
end

----| Functioning |----
TextButton.MouseMoved:Connect(UpdatePosition)
TextButton.MouseLeave:Connect(Remove)

Try this:

--//Services
local UserInputService = game:GetService("UserInputService")

--//Variables
local TextLabel = script.Parent
local TextButton = TextLabel.Parent

--//Functions
TextButton.MouseMoved:Connect(function()
	TextLabel.Visible = true
	TextLabel.Position = UDim2.fromOffset(UserInputService:GetMouseLocation().X, UserInputService:GetMouseLocation().Y)
end)

TextButton.MouseLeave:Connect(function()
	TextLabel.Visible = false
end)
1 Like

Tried it, still doesn’t work :frowning:

Is the TextLabel just not positioned right or can you not see it?

Also, is the anchor point for the TextLabel 0.5, 0.5?

Oh, the anchor point is 0, 0 ill try setting it to 0.5,0.5

Tried setting it to 0.5,0.5, nothing really changed, and I can see it, the y position is follow my mouse, but the y pos is like way far down


Heres a video I took of the problem.

Is the TextLabel’s position set to only offset and no scale?

It works perfectly fine for me:

Yep, and the parent of the textbutton btw is a scrollingframe if that changed anything.

Fixed it, this probably isn’t the best solution but, I just misused the Y position of the mouse by 250.

2 Likes

textbutton btw is a scrollingframe if that changed anything.

You probably should have provided this detail at the start. The ‘TextButton’ object’s position is going to be influenced by the position of the ‘ScrollingFrame’ by virtue of the former being a child of the latter.

Instead of ‘250’ incorporate ScrollingFrame.AbsolutePosition.Y into your code.

1 Like

You have to change the property of .AbsolutePosition of the scrolling frame for this to work as @Forummer explained.