Destroy an accessory upon equipping another

I’m trying to make a system that destroys an accessory (back accessory in this case) that has a certain bool value in it upon an click detector being activated.

For example I have 2 back accessories that I own in the game. Let’s say I equip the first one then I want to switch to the second one. I want to make it so if I equip the second one with my first one still equipped, the first one will be replaced by the second one and vice versa.

The issue is, I don’t know how, I added a bool value to the said accessories and tried to detect the said bool value and delete its parent upon the click detector/s being activated.

The script I tried using:

local click = script.Parent

click.MouseClick:Connect(function(plr)
	local char = plr.Character or plr.CharacterAdded:wait()
	local hum = char.Humanoid
	local Replicated = game:GetService("ServerStorage")
	local hat = Replicated.Microwaves:WaitForChild("Easybake Microwave"):Clone()
	local item = game.ServerStorage.Microwaves["Easybake Microwave"]
	if plr.Character:FindFirstChild("Easybake Microwave") and plr:FindFirstChild("OwnedTools"):FindFirstChild(item.Name) then
		plr.Character:FindFirstChild("Easybake Microwave"):Destroy()
	else
		if plr:FindFirstChild("OwnedTools"):FindFirstChild(item.Name) then
			plr.Character:FindFirstChildOfClass("Accessory"):FindFirstChild("Micro").Parent:Destroy()
			hum:AddAccessory(hat)
			script.Parent.Parent.Cloth:Play()
		else
			if plr.leaderstats.Money.Value <= -1 then
				script.Parent.Parent.error:Play()
			else
				script.Parent.Parent["ui_buy"]:Play()
				hum:AddAccessory(hat)
				plr.leaderstats.Money.Value -= 0
				game.ReplicatedStorage.Remotes.BuyTool:Fire(plr, item.Name)
			end
		end
	end 

end)

probably store the accessories in a table, do table[1]:Destroy() and that’ll remove it

How would I script that ? Sorry but I really have no idea on how I could do that.

When it puts on an accessory use table.insert(table, accessory), then you can see if it has 2 using #table >1 and if so table.remove(table, 1)

Ignore the # making it appear weird, you get the idea.

I still don’t really understand how I could script that into my code. Sorry.

Okay, whenever you put it on put it in the table using table.insert()
Then have an if statement asking if #table > 1.
If it is then run these lines:
table[1]:Destroy()
table.remove(table, 1) (If it ends up not working after first time running remove this line)

Hope this helps.