I want to achieve an image button that when clicked 1st time Puts the accessory on character. then 2nd time takes off character. I made it work where u can only put it on and not take off. But I’m not sure how to make it so it removes on the second click.
local insertS = game:GetService("InsertService")
local value = true
script.Parent.MouseButton1Down:Connect(function()
local asset
local char = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Character
local success = pcall(function()
asset = insertS:LoadAsset(11769104697)
end)
if not success then return end
local child = asset:GetChildren()
for _,v in pairs(child) do
if v:IsA("Accessory") and value then
value = false
char.Humanoid:AddAccessory(v)
if value == false then
value = true
v:Destroy()
end
end
end
end)
local insertS = game:GetService("InsertService")
local value = true
script.Parent.MouseButton1Down:Connect(function()
local asset
local char = script.Parent.Parent.Parent.Parent.Parent.Parent.Parent.Character
local success = pcall(function()
asset = insertS:LoadAsset(11769104697)
end)
if not success then return end
local child = asset:GetChildren()
for _,v in pairs(child) do
if v:IsA("Accessory") and value then
value = false
char.Humanoid:AddAccessory(v)
if value == false then
value = true
v:Destroy()
end
end
end
end)
I removed the conditional check ’ if value == false because it is unnecessary. Instead, I’ve added an "else’ block where char.Humanoid:RemoveAccessory(v) is called to remove the accessory when
'value is false. This way, the accessory will be added on the first click and removed on the second click.