Problem with attaching accessories on client

Hey developers,

I’ve come across a problem in a game I am working on where I’m putting accessories on dummies in a viewport frame, so like a character customizer (which is exactly what it is). Now, accessories don’t automatically attach to the head on the client, which is why I need to use a script to make it attach.

This is the script I got from someone with a few changes:

return function(accessory, charModel)
	local handle = accessory:FindFirstChild("Handle") --accessory:FindFirstChildWhichIsA("BasePart")
	-- The hair must be welded because AddAccessory doesn't work locally
	-- Noted 8/2/2021
	local accessoryAttachment = handle:FindFirstChildWhichIsA("Attachment")
	local characterAttachment = charModel.Head:WaitForChild(accessoryAttachment.Name)
	
	--print(accessoryAttachment == nil, characterAttachment == nil)

	local weld = Instance.new("Weld",handle)
	
	accessory.Parent = charModel
	
	weld.Part0 = charModel.Head
	weld.Part1 = handle
	weld.C0 = characterAttachment.CFrame
	weld.C1 = accessoryAttachment.CFrame
	
	--print(weld.C0, weld.C1)
	
	weld.Parent = handle
end

It doesn’t really work, and doesn’t attach it. I’m wondering if there is a better way to do this, otherwise what would be a good fix to this.

Thank you.

By doesn’t work, what I think you mean is putting the accessories on and nothing is happening? Try slapping a WorldModel in the ViewPort frame.

Also, using the second parameter in Instance.new() is bad practice, and causes slight memory leaks.

For some reason someone told me to put the parent thing in the Instance.new() and I did it which does nothing :open_mouth: gasp. I just forgot to change it back.

Anyways it worked, thanks.

1 Like