I need the SelectionBox (that's instanced by the following LocalScript on my Pickaxe tool) to be only visible when the tool's equipped, and when it's unequipped, it's destroyed/invisible.

I tried using tool.Unequipped but for some reason the SelectionBox is always there.

--[Locals]--
 
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local folders = workspace.OreBlocks
local tool = script.Parent

local selection = Instance.new("SelectionBox")
selection.Color3 = Color3.new(255,255,255)
selection.Parent = player.PlayerGui
selection.Name = ("PickaxeSelection")
selection.LineThickness = 0.09

--[Logic]--
 
local function onEquipped()
mouse.Move:connect(function()
	local target = mouse.Target
	
	if not target then 
		selection.Adornee = nil
	else if target.Parent == folders then
		selection.Adornee = target
	else
		selection.Adornee = nil
			end	
		end
	end)
end

tool.Equipped:connect(onEquipped)

1 comment

0

It's "elseif" not "else if". Any other error in the output?