How to make an outline when the mouse hovers over an object (while using a tool)

Hello! I am making a mining system and I want to add a SelectionBox hover-over system, if that makes sense. Let me show you what I mean:


While the player hovers on this rock while using a tool, it will show a SelectionBox.


When the players hovers off the rock, it will remove the SelectionBox.

I really don’t how to do this efficiently. I tried using Mouse.Move() but that didn’t work too well.

Try making a billboard GUI in the part and use this:

local Input = game:GetService("UserInputService")
local LocalPlayer = game.Players.LocalPlayer
local Mouse = player:GetMouse()  

Input.InputChanged:Connect(function(i)
	if Mouse.Target then
		if Mouse.Target:FindFirstChild("billboardguiname") then
		    -- do stuff
		else
			-- remove the else or do stuff here
		end
	end
end)

Perhaps this may help:

Also with my script you can put anything you want in the part. Just make sure to do Mouse.Target:FindFirstChild("partname")

I’m trying to do this with a SelectionBox, not a BillboardGui.

Yes but with that script you can detect it

Basically,

local event

tool.equiped:connect(function()
event = UIS.InputChanged:Connect(function(input)
if mouse.Target then
–Selection box

  end
 end)

end)

tool.unequiped:connect(function() event:Disconnect() end)

Make a new tool and put a localscript in the tool. In the parts that you want a selectionbox whenever you hover over it, put anything (i put a texture) in that part named Part4.

local equipped = false
local Tool = script.Parent
local UserInputService = game:GetService("UserInputService")

local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local selectionBox = false

UserInputService.InputChanged:Connect(function(input,isTyping)
	if not isTyping then
		local mouseTarget = mouse.Target
		if mouseTarget and plr.Character:FindFirstChild(script.Parent.Name) then
			if mouseTarget.Name == "Part" then
				local partdescendant = mouse.Target:FindFirstChild('Part4')
				if partdescendant and selectionBox ~= true then
					selectionBox = true
					local selectionBox = Instance.new("SelectionBox")
					selectionBox.Parent = partdescendant.Parent
					selectionBox.Adornee = partdescendant.Parent
				end
			end
		else
			for i,v in pairs(game:GetDescendants()) do
				if v:FindFirstChild("Part4") and v:FindFirstChild("SelectionBox") and v.Name == "Part" then
					v.SelectionBox:Destroy()
				end
				selectionBox = false
			end
		end
	end
end)

Do you want it so if you hover over any part, it’ll show a selection box? this only does it for specific parts.

This works, but when I hover off the part, the selection box is still there. Sorry for necroposting, just came across the issue today.