Hello, recently i have been trying to make an accessory manager that display’s all of the local player’s accessories in a form of imagebuttons and their assigned asset thumbnails, and when a player clicks on the corresponding imagebutton it would remove the accessory.
But ive ran into an issue, and this that i dont know how to make the removing accessory part.
Here is my script:
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local button = script.Parent
local parentGui = button.Parent
button.MouseButton1Click:Connect(function()
if humanoid then
local humanoidDescription = humanoid:GetAppliedDescription()
local accessoryTypes = {"HatAccessory", "HairAccessory", "FaceAccessory", "NeckAccessory", "ShouldersAccessory", "FrontAccessory", "BackAccessory", "WaistAccessory"}
for _, accessoryType in ipairs(accessoryTypes) do
local accessories = humanoidDescription[accessoryType]
if accessories and accessories ~= "" then
local accessoryIds = string.split(accessories, ",")
for _, accessoryId in ipairs(accessoryIds) do
local newButton = Instance.new("ImageButton")
newButton.Image = "rbxthumb://type=Asset&id=" .. accessoryId .. "&w=420&h=420"
newButton.Parent = parentGui.Frame.ScrollingFrame
newButton.MouseButton1Click:Connect(function()
for _, accessory in ipairs(character:GetChildren()) do
if accessory:IsA("Accessory") then
local mesh = accessory:FindFirstChild("Handle")
if mesh then
local assetId = tonumber(mesh.MeshId:match("id=(%d+)"))
if assetId == tonumber(accessoryId) then
accessory:Destroy()
break
end
end
end
end
end)
end
end
end
end
end)
And here is a video of how to it works:
If someone could correct me on how to make the corresponding accessory destroy when you click on the corresponding imagebutton , it would be really heapfull.