I have tested my method for over 1 hour - I figured out how to create the replacement accessory and add a part, and inside the part named "Handle", added the mesh that the hat contains and the attachment. The only problem is the weld. All of the hats that I copy onto another person seems to get stuck in the same place by the neck area, and putting the accessory weld's C0 onto the new accessory's C0 does NOT work.
My script:(error will be in comment)
local plr = game.Players.LocalPlayer local player = desiredPlayer for _,v in pairs(player.Character:GetChildren()) do if v:IsA("Accessory") then local hat = Instance.new("Accessory", plr.Character) hat.AttachmentForward = v.AttachmentForward hat.AttachmentPos = v.AttachmentPos hat.AttachmentRight = v.AttachmentRight hat.AttachmentUp = v.AttachmentUp local handle = Instance.new("Part", hat) handle.Name = "Handle" handle.CFrame = plr.Character.Head.CFrame handle.Size = v.Handle.Size handle.CanCollide = false local mesh = Instance.new("SpecialMesh", handle) mesh.MeshId = v.Handle.Mesh.MeshId mesh.Offset = v.Handle.Mesh.Offset mesh.Scale = v.Handle.Mesh.Scale mesh.TextureId = v.Handle.Mesh.TextureId for _,vv in ipairs(v.Handle:GetChildren()) do if vv:IsA("Attachment") then local HairAttachment = Instance.new("Attachment", handle) HairAttachment.Name = "Attachment" HairAttachment.Orientation = vv.Orientation HairAttachment.Position = vv.Position HairAttachment.Axis = vv.Axis HairAttachment.SecondaryAxis = vv.SecondaryAxis end end local AccessoryWeld = Instance.new("Weld", handle) AccessoryWeld.Part0 = plr.Character["Head"] AccessoryWeld.Part1 = handle AccessoryWeld.C0 = v.Handle.AccessoryWeld.C0 -- everything works fine up until this point. the welds attach to the head, but NOT IN THE RIGHT POSITION!! I can't figure out any alternative to this!! AccessoryWeld.C1 = v.Handle.AccessoryWeld.C1 end end
I am sorry i did not realize welds went over. ok what i did to tackle this is first i ran a for loop to go through the first character until it found an Accessory. then i looked in the handle to see if i can find the Attachment. One cool thing is Roblox keeps Accessory Attachment's in the Handle and in the Player limbs the same name. so knowing this i wrote a for loop checking each part of player2's character until i found the Attachment named as the first. the code looks scary but in reality its simple.
function cloneHats(player1,player2) for _,v in pairs(player1.Character:GetChildren()) do if v:IsA("Accessory") then local acc= v:Clone() print(v.Name) local check=acc.Handle:FindFirstChildWhichIsA("Attachment") if check then for __i,char2 in pairs(player2.Character:GetChildren()) do local check2 = char2:FindFirstChild(check.Name) if check2 then local w = Instance.new("Weld") w.Part0 = acc.Handle w.Part1 = check2.Parent w.C0 = check2.CFrame acc.Parent = player2.Character end end end end end end cloneHats(playerFrom,playerTo) end