How to make highlight appear on part that the mouse hovers over?

I’m trying to get it so that when my mouse hovers over a part, a highlight object gets added to that part.

The current script I’m using is not working, not sure why.

local outline = script:WaitForChild("Selection")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

outline.Parent = plr:WaitForChild("PlayerGui")

mouse.Move:Connect(function()
	local target = mouse.Target

	for _,blocks in pairs(workspace.Blocks:GetChildren()) do
		if target == blocks then
			outline.Adornee = blocks
		else
			if (outline.Adornee == blocks) then
				outline.Adornee = nil
			end
		end
	end
end)

Any way to fix this?

3 Likes

Are you using a local script? Also where is the script located?

2 Likes

LocalScript, in the StarterGui

2 Likes

I think that’s the problem. Move it to StarterPlayerScripts and it should work.

Still not working, not sure why

I just tested it and it worked for me, not sure what the issue is.

Hi , i tried the script on my end and it worked just fine

local outline = script:WaitForChild("Selection")
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()

mouse.Move:Connect(function()
	local target = mouse.Target

	for _,blocks in pairs(workspace.Blocks:GetChildren()) do
		if target == blocks then
			outline.Adornee = blocks
		else
			if (outline.Adornee == blocks) then
				outline.Adornee = nil
			end
		end
	end
end)

i don’t know what is this for

outline.Parent = plr:WaitForChild("PlayerGui")

So i deleted it

Screen Shot 2023-08-16 at 7.13.59 PM

Yeah me too
image

Maybe it doesn’t work with cloned parts? Or because the part name is random.
There is a script that randomizes the part name everytime it’s cloned, and I want it to select the cloned part.
Screen Shot 2023-08-16 at 7.19.20 PM

Yeah I have it in the exact spot and it worked fine on my end.

DeleteLater

Yeah in the game I’m using this in, there is a textbox that adds a part when I type “add”

It also uses HttpService to randomize the name of the part.

local HttpService = game:GetService("HttpService")

local id = HttpService:GenerateGUID(true)
partClone.Name = string.sub(id, 2, 8) --keeps string length short

(partClone is the cloned part that gets added)

No, it doesn’t make a difference.

I tested if with duplicated and differently named parts, which caused no issue. Is ‘Blocks’ a folder as I assumed?

Selections only render if they’re parented to workspace. When I personally work with selection options I just put them in the local camera and leave it at that

Forgot we’re working with Highlights that dont have this weird restriction

What How ?
image
it still works for me

1 Like

Didn’t know it specified a folder for use, thanks for pointing that out. :smiling_face_with_tear:

I wasn’t sure what else ‘Blocks’ was.

I would suggest instead of using Move, listen to changes to Target, you’ll send less events and improve performance since it will only fire when the target changes, and not when you move the mouse.

There’s some other tips I suggest like using IsDescendantOf instead of iterating over the children of the folder.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.