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

I need help to change the click detector appearance when some one hover over it?

Local Mouse = Player:GetMouse()

Local SHOWGUI = workspace:WaitForChild('SHOWGUI')

Local ScreenGui = script.Parent:WaitForChild('ScreenGui')
Local TextLabel = ScreenGui:WaitForChild('TextLabel')

game:GetService('RunService').RenderStepped:Connect(function()
Local X = Mouse.X
Local Y = Mouse.Y

if Mouse.Target then 
    If Mouse.Target.Name == 'SHOWGUI' then
TextLabel.Visible = true
TextLabel.Position = UDim2.new(0,X,0,Y)
else
   
TextLabel.Visible = false

I put the part named SHOWGUI in workspace but idk why it wont show for me.

3 comments

0

Well, for one, you are using "Local" instead of "local." The Lua language is case-sensitive.

0

Secondly, you have not closed the functions or if-statements with the appropriate "end" line.

0

Format your code correctly

1 answer

✓ Accepted answer
-- local doesn't have a capital L
-- It's LocalPlayer not LocalPlayer's'

local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
local SHOWGUI = workspace:WaitForChild('SHOWGUI')
-- The LocalScript should be inside ScreenGui
local ScreenGui = script.Parent
local TextLabel = ScreenGui:WaitForChild('TextLabel')
local cam = workspace.CurrentCamera

-- You can use Move event on your mouse to detect change
-- Use 'C'onnect, 'c'onnect is deprecated.
Mouse.Move:Connect(function()
	if Mouse.Target then 
		-- if is lowercase
		if Mouse.Target.Name == 'SHOWGUI' then 
			-- Takes the position of the part converts it to screen coordinates
			local world_toscreen = cam:WorldToScreenPoint(Mouse.Hit.p)
			-- Makes the label display in the middle of your mouse
			local xpos, ypos = world_toscreen.x  - (TextLabel.Size.X.Offset/2), world_toscreen.y  - (TextLabel.Size.Y.Offset/2)
			TextLabel.Visible = true 
			TextLabel.Position = UDim2.new(0,xpos,0,ypos) 
		else
			TextLabel.Visible = false
		end
	end
end)

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