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)