ADD accesory not working

HI devs when i try and add a acessory via a part to the player i get this error
AddAcessory failed: Accessory is already being worn by another character
can anyone help

debounce = true

function onTouched(hit)
	if (hit.Parent:findFirstChild("Humanoid") ~= nil and debounce == true) then
		print("run")
		debounce = false
		local old = hit.Parent:FindFirstChildWhichIsA("Accessory")
		if old then
			old:Destroy()
		end
		local h = game:GetService("ReplicatedStorage").Hat:Clone()--put hat name here
		h.Name = "Hat"
		h.Parent = hit.Parent
		h.AttachmentForward = Vector3.new (-0, -0, -1)
		h.AttachmentPos = Vector3.new(0, 0.092, 0)
		h.AttachmentRight = Vector3.new (1, 0, 0)
		h.AttachmentUp = Vector3.new (0, 1, 0)
		hit.Parent.Humanoid:AddAccessory(h)
		print("done")
		wait(5)
		debounce = true
	end
end

script.Parent.Touched:connect(onTouched)

Could it be because you parent the hat to the character before using AddAccessory? Try removing the h.Parent = hit.Parent line

1 Like

the error goes but the player moves to the hat

Is the hat anchored by any chance?

now my character doesn’t move to the hat but now the hat does not move

As in, it doesn’t move from its original pos set in ReplicatedStorage? Maybe instead of doing

local h = game:GetService("ReplicatedStorage").Hat:Clone()--put hat name here
		h.Name = "Hat"
		h.Parent = hit.Parent
		h.AttachmentForward = Vector3.new (-0, -0, -1)
		h.AttachmentPos = Vector3.new(0, 0.092, 0)
		h.AttachmentRight = Vector3.new (1, 0, 0)
		h.AttachmentUp = Vector3.new (0, 1, 0)
		hit.Parent.Humanoid:AddAccessory(h)

Just do

local h = game:GetService("ReplicatedStorage").Hat:Clone()--put hat name here
hit.Parent.Humanoid:AddAccessory(h)

And see if that fixes anything? If not, it may be something wrong with how the hat is set up, does it have the usual things (OriginalSize NumberValue, HatAttachment, etc) inside of it? Is the part in the accessory called “Handle”?

If you don’t have the usual things in the accessory’s Handle part, do a play test, go into one of your hat accessories form the explorer, copy everything i nthe Handle part and past ethem to your Hat’s handle part

still no it just spawns and does not move i have no attachments and also what do i do with a handle

If I know well, the part in the accessory that handles the appearance of it must be called “Handle”.

And for the attachment, you need a HatAttachment, I recommend doing what I had mentioned before

make sure the hat isn’t anchored in any of the parts.

done that i cant get the hat to folow the player