Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make it so text appears when i hover over a part?

so I want it so I can hover over a part with my cursor and text appears above my cursor and also, when I go a certain distance away from that part it won't show the text when I hover over it. Sorry, I'm a beginner at scripting.

so how would i make this script not show the text when i am a certain distance away?

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

local SHOWGUI = workspace:WaitForChild('PART TEST')

local ScreenGui = script.Parent:WaitForChild('ScreenGuiPart')
 local TextLabel = ScreenGui:WaitForChild('TextLabelThing')
 
game:GetService('RunService').RenderStepped:Connect(function()
 local X = Mouse.X
 local Y = Mouse.Y
 
 if Mouse.Target then 
  if Mouse.Target.Name == 'PART TEST' then 
   TextLabel.Visible = true
   TextLabel.Position = UDim2.new(0,X,0,Y + 50)
  else 
   TextLabel.Visible = false
  end
 end
end)

1 answer

Heya, you could make use of the mouse.Target property.

You could check if mouse.Target is a part inside mouse.Move, eg :

mouse.Move:Connect(function()
if mouse.Target then
-- code
end
end)

to check the distance, you can use magnitude, like so

(playerPart.Position - partWeAreCheckingWith.Position).magnitude

4 comments

0

so how would i use the magnitude feature into my code? im kind of a noob

0

(character.HumanoidRootPart.Position - mouse.Target.Position).magnitude

0

im sorry if im asking much, but where do i put that in my code? i tried to but i just ended up with nothing

0

nvm i found the extremely scuffed solution since i dont know how to use magnitude: i just insert a transparent part on top of the part that has the text, so when i go away from the part with the text, my mouse is on the transparent part therefore the text is not shown

This discussion is preserved as it was. New answers, comments, and votes are closed.