SelectionBox not appearing/functioning - Really need help

This is into a localscript, inside a tool. The purpose of it is to highlight an ore to let the player know what’s gonna mine. I solved a problem where it would create SelectionBoxes each time the mouse moved with the debounce but now the appears to not work and I really don’t know why.

selection.Adornee = part

local tool = script.Parent
local player = game.Players.LocalPlayer
local clickDet = game.Workspace.Copper.ClickDetector

local function onEquipped()
	local mouse = player:GetMouse()
	local modelMode = true  -- if true, select models rather than parts	
	local debounce = false
	local selection = Instance.new("SelectionBox")
	selection.Color3 = Color3.new(0.6,0.6,0,6)
	
	mouse.Move:Connect(function() --When the mouse moves
		local target = mouse.Target
		
		
		if not target then
			-- nothing selected
			selection.Adornee = nil
		elseif modelMode then
			
			-- when in model mode, try and select the parents first
			if target.Parent:IsA("Model") and not debounce then
				selection.Parent = player.PlayerGui
				local part = target.Parent:WaitForChild("HighlightPart")
				selection.Adornee = part	
				
				debounce = true
			else
				selection.Adornee = nil
			end
		end
	end)
end

tool.Equipped:Connect(onEquipped)

Any suggestions for making this better and/or solving the problem is appreciate it.

2 Likes