Answered by
6 years ago Edited 6 years ago
Courtesy of TheGamer101 on this DevForum post.
This is because Accessory welds are currently created on the server only, never the client. This is intended right now but we might change it to make this easier to work with when using FilteringEnabled.
Here is some code you can use to add an Accessory to a humanoid locally:
01 | function weldAttachments(attach 1 , attach 2 ) |
02 | local weld = Instance.new( "Weld" ) |
03 | weld.Part 0 = attach 1. Parent |
04 | weld.Part 1 = attach 2. Parent |
05 | weld.C 0 = attach 1. CFrame |
06 | weld.C 1 = attach 2. CFrame |
07 | weld.Parent = attach 1. Parent |
10 | local function buildWeld(weldName, parent, part 0 , part 1 , c 0 , c 1 ) |
11 | local weld = Instance.new( "Weld" ) |
20 | local function findFirstMatchingAttachment(model, name) |
21 | for _, child in pairs (model:GetChildren()) do |
22 | if child:IsA( "Attachment" ) and child.Name = = name then |
24 | elseif not child:IsA( "Accoutrement" ) and not child:IsA( "Tool" ) then |
25 | local foundAttachment = findFirstMatchingAttachment(child, name) |
26 | if foundAttachment then |
27 | return foundAttachment |
32 | function addAccoutrement(character, accoutrement) |
33 | accoutrement.Parent = character |
34 | local handle = accoutrement:FindFirstChild( "Handle" ) |
36 | local accoutrementAttachment = handle:FindFirstChildOfClass( "Attachment" ) |
37 | if accoutrementAttachment then |
38 | local characterAttachment = findFirstMatchingAttachment(character, accoutrementAttachment.Name) |
39 | if characterAttachment then |
40 | weldAttachments(characterAttachment, accoutrementAttachment) |
43 | local head = character:FindFirstChild( "Head" ) |
45 | local attachmentCFrame = CFrame.new( 0 , 0.5 , 0 ) |
46 | local hatCFrame = accoutrement.AttachmentPoint |
47 | buildWeld( "HeadWeld" , head, head, handle, attachmentCFrame, hatCFrame) |
Using addAccoutrement(character, accoutrement) is how you would add it to the character. Character being your character and accoutrement being the Accessory.