I am trying to make it so that when a GUI is clicked, the accessories will change.
It removes the current accessories, but it doesn’t add the new ones
here is the script
local Avatar = game.Workspace.Character.MainAvatar
script.Parent.MouseButton1Click:Connect(function()
local descendants = Avatar:GetDescendants()
for _, descendant in pairs(descendants) do
if descendant:IsA("Accessory") then
descendant:Destroy()
end
end
local accessories = script:GetDescendants()
for _, descendant1 in pairs(accessories) do
if descendant1:IsA("Accessory") then
local main = descendant1:Clone()
main.Parent = Avatar
end
end
end)
local Avatar = game.Workspace.Character.MainAvatar
script.Parent.MouseButton1Click:Connect(function()
local descendants = Avatar:GetDescendants()
for _, descendant in pairs(descendants) do
if descendant:IsA("Accessory") then
descendant:Destroy()
end
end
local accessories = script:GetDescendants()
for _, descendant1 in pairs(accessories) do
if descendant1:IsA("Accessory") then
local main = descendant1:Clone()
Avatar.Humanoid:AddAccessory(main)
end
end
end)