Making an accessory GUI

Hey, I’m making a GUI where you can click a button to equip an accessory to your character.
Everything works perfectly, except that I want a way to remove an accessory if the player clicks the button again after they put it on.
How can this be done?
This is my code:

Client side


local CapeEvent = game:GetService("ReplicatedStorage").EquipAccessoryCape
script.Parent.MouseButton1Down:Connect(function()
	CapeEvent:FireServer("EquipAccessoryCape", game:WaitForChild("Lighting").Accessories.Cape)
end)

Server side:

local RemoteEvent = game.ReplicatedStorage:WaitForChild("EquipAccessoryCape")
local hascape = false

RemoteEvent.OnServerEvent:Connect(function(player, topic, info)
	if topic == "EquipAccessoryCape" and hascape == false then
		local newAccessory = info:Clone()
		newAccessory.Parent = player.Character
		hascape = true
     end
end)

Any help is appreciated.

2 Likes

You can tag the added accessories with CollectionService and then delete the tagged accessories when the player clicks the button again

make something like “local thing = player.Character:FindFirstChild(“Accesory_name”) if thing then thing:destroy”