Removing a certain acessory from a character

I want to remove a specific accessory inside the character.
The “RemoveAccessories” is removing all accessors inside the character.
The variable “item” is returning the name Halo1 (which is the accessory i want to remove from inside the character.

How can I do that?

-- this script is inside a button

local equipped = script.Parent.Parent.Equipped
local unequipped = script.Parent.Parent.Unequipped
local replicatedStorage = game:GetService("ReplicatedStorage")
local gearEvent = replicatedStorage:WaitForChild("Unequip")
local halo = script.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
	local item = halo.Name
	print(item) -- is printing Halo1
	gearEvent:FireServer(item)
	unequipped.Visible = false
	equipped.Visible = true 
end)

-- this script is on SSS

local replicatedStorage = game:GetService("ReplicatedStorage")
local unequip = replicatedStorage:WaitForChild("Unequip")
local hat = replicatedStorage.Halos

unequip.OnServerEvent:Connect(function(player, item)
	local character = player.Character
	local humanoid = character.Humanoid
	local clone = hat[item]
	humanoid:RemoveAccessories(clone)
end)

You can get all the accessories using GetAccessories and check if an accessory name matches the accessory you want to destroy

-- this script is on SSS

local replicatedStorage = game:GetService("ReplicatedStorage")
local unequip = replicatedStorage:WaitForChild("Unequip")
local hat = replicatedStorage.Halos

unequip.OnServerEvent:Connect(function(player, item)
	local character = player.Character
	local humanoid = character.Humanoid
	local clone = hat[item]
	for _,accessory in pairs(humanoid:GetAccessories()) do
		if accessory.Name ~= item then
			continue
		end
		accessory:Destroy()
		break
	end
end)

Or this, not sure if this below will work, best you use the one above

-- this script is on SSS

local replicatedStorage = game:GetService("ReplicatedStorage")
local unequip = replicatedStorage:WaitForChild("Unequip")
local hat = replicatedStorage.Halos

unequip.OnServerEvent:Connect(function(player, item)
	local character = player.Character
	local humanoid = character.Humanoid
	local accessories = humanoid:GetAccessories()
	local clone = hat[item]
	local found = table.find(accessories, clone)
	if not found then 
		return
	end
	accessories[found]:Destroy()
end)

the first script worked … tysm

1 Like