Why won't my accessory gui work

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)
1 Like

I think I fixed it.

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)
3 Likes

thank you but what did you change im pretty sure its identical to mine.

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.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.