-- MouseEnter
script.Parent.MouseEnter:Connect(function()
script.Parent.FollowLabel.Visible = true
end)
-- MouseLeave
script.Parent.MouseLeave:Connect(function()
script.Parent.FollowLabel.Visible = false
end)
-- FollowLabel
local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Move:Connect(function()
script.Parent.FollowLabel.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
end)
This script makes a TextLabel follow LocalPlayer’s mouse cursor when they hover over a GUI, but it’s too far away from the cursor, how do I fix this?
1 Like
Iemny
(Iemny)
March 6, 2024, 1:43pm
#2
The Mouse.X
and Y
are exactly at the point of the cursor, and you also input it correctly into the UDim2
(offset, not scale), so the only thing I can guess that is the issue is that the FollowLabel is in a Frame
, or perhaps a Frame
inside of a Frame
. When these overlap, it can cause issues with the offset
, so make sure you make a separate frame with the label inside of it like so;
I tried this and it worked for me.
Iemny
(Iemny)
March 6, 2024, 2:03pm
#4
Yes, I think that is the issue, since the label is ‘inside’ of the TextButton
on the left side of your screen.
All you have to do is copy my explorer.
Make a Frame
, child of the ScreenGui
. Make the frame the size you want the FollowLabel
to be.
Put the TextLabel
inside of the Frame
, setting it’s UDim2
size to 1, 0, 1, 0
(xScale and yScale to 1).
If preferred, put the LocalScript
as a child of the Frame
. Set the correct paths accordingly.
This should resolve the issue.
I get an error saying “FollowLabel is not a valid member of Frame “Players.SleepyUnnamed.PlayerGui.ScreenGui.Frame””
Heres the script:
-- MouseEnter
script.Parent.Parent.EnableHitbox.MouseEnter:Connect(function()
script.Parent.FollowLabel.Visible = true
end)
-- MouseLeave
script.Parent.Parent.EnableHitbox.MouseLeave:Connect(function()
script.Parent.FollowLabel.Visible = false
end)
-- FollowLabel
local Mouse = game.Players.LocalPlayer:GetMouse()
Mouse.Move:Connect(function()
script.Parent.FollowLabel = UDim2.new(1, Mouse.X, 1, Mouse.Y)
end)
Explorer:
Iemny
(Iemny)
March 6, 2024, 2:33pm
#6
Note:
You still have the original pathing, which is incorrect now.
I’ll give you the curtesy of fixing it for you;
local playerMouse = game.Players.LocalPlayer:GetMouse()
local enableHitbox = script.Parent.Parent:FindFirstChild("EnableHitbox")
-- MouseEnter
enableHitbox.MouseEnter:Connect(function()
script.FollowLabel.Visible = true
end)
-- MouseLeave
enableHitbox.MouseEnter:Connect(function()
script.FollowLabel.Visible = false
end)
-- FollowLabel
playerMouse.Move:Connect(function()
script.Parent.FollowLabel.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
end)
error “FollowLabel is not a valid member of LocalScript “Players.SleepyUnnamed.PlayerGui.ScreenGui.Frame.FollowLabelScript””
Iemny
(Iemny)
March 6, 2024, 2:45pm
#8
I believe you could have fixed this yourself…
Correction of the script;
local playerMouse = game.Players.LocalPlayer:GetMouse()
local enableHitbox = script.Parent.Parent:FindFirstChild("EnableHitbox")
-- MouseEnter
enableHitbox.MouseEnter:Connect(function()
script.Parent.FollowLabel.Visible = true
end)
-- MouseLeave
enableHitbox.MouseEnter:Connect(function()
script.Parent.FollowLabel.Visible = false
end)
-- FollowLabel
playerMouse.Move:Connect(function()
script.Parent.FollowLabel.Position = UDim2.new(0, Mouse.X, 0, Mouse.Y)
end)
Players.SleepyUnnamed.PlayerGui.ScreenGui.Frame.FollowLabelScript:16: Expected identifier when parsing expression, got ‘[’
Iemny
(Iemny)
March 6, 2024, 2:56pm
#10
There is not a ‘[’ in the script I provided, so that’s a typo you must’ve made.
system
(system)
Closed
March 20, 2024, 2:56pm
#11
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.