-
What do you want to achieve? Keep it simple and clear!
I want to make so the local script removes the text that is created under the players mouse after looking away, the game is in first person. -
What is the issue? Include screenshots / videos if possible!
I have managed to get the script to detect if the object that the mouse is pointing towards has a string value and a tag called “ForText” signed to it and also added a max activation distance using magnitude that checks the parts distance and humanoid distance. However I think my issue is that the script does not get past “label Visible = true” how do I know that is the issue? Because I have added two prints, one before the “else” statement and one after the “else” statement.
When this issue happens it doesn’t disable the text that got visible after the player looks away from the part, the text is supposed to only be visible when the player is looking at the part.
Example of issue:
-
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I have tried moving the “end” statement but I’m not sure if I have done correctly or if that even is the key to fixing the issue
-- local player = game:GetService('Players').LocalPlayer
local mouse = player:GetMouse()
local label = player.PlayerGui.MouseHoverText.TextLabel
local Thepart = game.Workspace.thehmm.hmm
local character = player.Character or player.CharacterAdded:wait()
local HumanoidRootPart = character:WaitForChild('HumanoidRootPart')
local CollectionService = game:GetService("CollectionService")
function updatePos()
local workDistance = 6
local target = mouse.Target
if (Thepart.Position - HumanoidRootPart.Position).magnitude < workDistance then--magnitude checks the player distance
if CollectionService:HasTag(mouse.Target, "ForText") then ---Checks if the object is asigned to any tags
if target and target:FindFirstChild("MousehoverText") then ---Checks if the object has MousehoverText
label.Position = UDim2.fromOffset(mouse.X, mouse.Y) ---puts the Textlabel under the mouse
label.Text = target.MousehoverText.Value
label.Visible = true ------does not get past this line
print("test1")
else
label.Visible = false
print("test2")
end
elseif (Thepart.Position - HumanoidRootPart.Position).magnitude > workDistance then
label.Visible = false
end
end
end
mouse.Move:Connect(updatePos)
updatePos()