I have custom accessories that I am trying to equip on the player. Following the devhub article for AddAccessory, I am still unable to get the accessory to equip. Here’s what I’m doing.
The Accessory has an Attachment.
The Attachment objects in the Accessory objects all match the names of Attachment objects in the default character (for the record, I am using R6 but I don’t think this matters).
I tried anchoring the parts in the Accessory but that only teleported my character to the default position of the parts before immediately disappearing.
I even tried doing a sequence that goes along the lines of this, and it does not hang!
repeat
humanoid:AddAccessory(accessory)
wait()
until accessory.Parent == humanoid.Parent
Instead of the intended behavior of equipping to the player and the accessory remaining with the character as its parent, it just deletes immediately irrespective of if I leave it anchored or not.
Is there anything I’m missing? It’s weird because it’s not my first time using AddAccessory as I’ve gotten it to work before on a different project.
Update: After trying to manually copy and paste the attachments into my character, it immediately deletes itself so it’s definitely not a problem with AddAttachment itself. Archivable is set as true.
I tried both anchoring and unanchoring. Neither works. Sorry – should have made that clear; I’m aware that it’s not supposed to be anchored.
And Something Else too, you want to give the accessory to the player when it joins the game?
No, but in a special inventory page that I’m in the middle of creating. It’s also worth mentioning that I send a request from the client to equip the accessories, so the server calls AddAccessory.
The ones I’m testing right now are named HatAttachment.
My understanding though is that if the attachment is not found then it still parents it inside the character but just doesn’t attach. However, this is not the case and it is immediately deleted.
I made an update to the original post, but I found out that manually copying and pasting into the character doesn’t work either. Thus, I don’t think the problem is in my code but I can share it anyways:
for _, accessory in pairs(Items[itemType][itemName]:GetChildren()) do
-- These are legitimate accessories; I printed to test this theory
if accessory:IsA("Accessory") then
local newAccessory = accessory:clone()
repeat
humanoid:AddAccessory(newAccessory)
wait() -- overkill but used when calling AddAccessory once didn't work; still doesn't work
until newAccessory.Parent == character
end
end