Why is this text label not correctly following the mouse?

Hi, my name is King. I’m trying to make this text label follow the mouse correctly. I got it kind of working but it’s not working properly.

The issue is that the mouse is not following the exact pointer position!

Here is the properties tab.
image

Also, I’m getting no errors in the output.

I couldn’t find anything helpful on the developer hub.

Here’s the code:

button.MouseEnter:Connect(function()
	script.Parent.Parent.Hint.Visible = true
end)

button.MouseLeave:Connect(function()
	script.Parent.Parent.Hint.Visible = false
end)

local mouse = game.Players.LocalPlayer:getMouse()

mouse.Move:connect(function()
	script.Parent.Parent.Hint.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
end)

Any help would be appreaciated.

1 Like

Okay, I will try the code right now!

I do not see the GUI when I used that. When I checked on the studio, I saw the position moving and it was visible when my mouse entered the area of the GUI, but it wasn’t showing on my screen.

I only put the code that runs that system. But I’ll do full code.

local button = script.Parent
local enabled = false
local cooldown = script.Parent.Cooldown
local savedata = game.ReplicatedStorage.SaveData

button.MouseButton1Click:Connect(function(player)
	if enabled == false and cooldown.Value == 0 then
		savedata:FireServer(player)
		enabled = true
		button.Text = "Saving your data, do not leave the game"
		wait(0.2)
		button.Text = "Saving your data, do not leave the game."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game.."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game..."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game"
		wait(0.2)
		button.Text = "Saving your data, do not leave the game."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game.."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game..."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game"
		wait(0.2)
		button.Text = "Saving your data, do not leave the game."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game.."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game..."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game"
		wait(0.2)
		button.Text = "Saving your data, do not leave the game."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game.."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game..."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game"
		wait(0.2)
		button.Text = "Saving your data, do not leave the game."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game.."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game..."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game"
		wait(0.2)
		button.Text = "Saving your data, do not leave the game."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game.."
		wait(0.2)
		button.Text = "Saving your data, do not leave the game..."
		wait(0.2)
		button.Text = "Data successfully saved!"
		wait(1)
		button.Text = "Manually Save Data"
		enabled = false
		cooldown.Value = 60
	elseif cooldown.Value <= 60 and cooldown.Value > 1 and enabled == false then
		enabled = true
		button.Text = "You must wait "..cooldown.Value.." more seconds until you can save again!"
		wait(1)
		button.Text = "Manually Save Data"
	enabled = false
	end
end)

button.MouseEnter:Connect(function()
	script.Parent.Parent.Hint.Visible = true
end)

button.MouseLeave:Connect(function()
	script.Parent.Parent.Hint.Visible = false
end)

local mouse = game.Players.LocalPlayer:getMouse()

mouse.Move:Connect(function()
	script.Parent.Parent.Hint.Position = UDim2.new(mouse.X, 0, mouse.Y, 0)
end)

The one called “Hint” is not showing up on screen. But when I check properties it’s visible but it just won’t show.

The reason why I only provided this is because this is the code I need help on fixing everything else if perfectly fine in the script.

button.MouseEnter:Connect(function()

script.Parent.Parent.Hint.Visible = true

end)

button.MouseLeave:Connect(function()

script.Parent.Parent.Hint.Visible = false

end)

local mouse = game.Players.LocalPlayer:getMouse()

mouse.Move:Connect(function()

script.Parent.Parent.Hint.Position = UDim2.new(mouse.X, 0, mouse.Y, 0)

end)

The first and third arguments of UDim2.new() are scale. The mouse positions are offset. The following should be done instead:

UDim2.new(0, mouse.X, 0, mouse.Y)

I clicked solution button instead of reply, but I will try it.

It still does the bug / issue.

What does it do this time? Is it moving at all?

It is moving, but the gui is faw away from the mouse.

I know why this is.

The position of any GUI Object is based on the AnchorPoint.

By default, the AnchorPoint of GUI Objects is (0,0), which is the top left corner of the object.

To solve this, set the AnchorPoint property of the TextLabel to (0.5,0.5), which is the center.

Do I set that in the script or in the propterties menu? (sorry I’m not that familiar with this type of stuff)

Set it in the properties menu.

Also just a note that the video you sent is private, but this might just solve your issue.

Oh, my bad. But I will try it!

Edit: Testing now. (roblox studio play button is so slow)

It is now closer to the mouse. But still far. Should I just keep messing around with it until it gets perfect?

I would like to note that this isn’t my preferred way of doing this, because the mouse would be in the dead center of the TextLabel. I am going to further investigate this myself.

Allow me a few to test this out.

1 Like

Hey. I found out the issue.

The Hint TextLabel is a descendant (inside) of the Profile frame.

In order to resolve your issue, the Hint TextLabel needs to be outside of the Frame, and inside the Profile GUI. You may need to resize it.

This is a visual explanation: https://gyazo.com/ab52bfc79d70e190edb32c89fbce1322

Okay, thank you! I’m trying it right now. I will edit this message if it worked.