Easy way to put accessories on a rig that's in a viewport frame?

Hey, so I just found out that accessories don’t render in viewport frames, and I’m trying to find a workaround to CFrame the handle of that hat and put it on the rig in the same position as it would be in if I drop the accessory in the rig.

Any ideas?? Thanks.

Hi!
Here is a function that should works.

Credits : Humanoid:AddAccessory does not work with FE from a LocalScript - #3 by teamkilled

local function addAccessory(character, accessory)
	local attachment = accessory.Handle:FindFirstChildOfClass("Attachment")
	local weld = Instance.new("Weld")
	weld.Name = "AccessoryWeld"
	weld.Part0 = accessory.Handle
	if attachment then
		local other = character:FindFirstChild(tostring(attachment), true)
		weld.C0 = attachment.CFrame
		weld.C1 = other.CFrame
		weld.Part1 = other.Parent
	else
		weld.C1 = CFrame.new(0, character.Head.Size.Y / 2, 0) * accessory.AttachmentPoint:inverse()
		weld.Part1 = character.Head
	end
	accessory.Handle.CFrame = weld.Part1.CFrame * weld.C1 * weld.C0:inverse()
	accessory.Parent = character
	weld.Parent = accessory.Handle
end

To call the function just do :

addAccessory(charOfTheViewPortFrame, accesoryYouWantToPut)

Hope it helped

11 Likes

Thank you! Although, this is why this is a bit of a tricky problem, because welds don’t function in viewport frames either…

:confused:

1 Like

Yep, i worked last week on a character custom and it was weird to see how to do that :joy:

1 Like

Still searching for a way to do this…I mean worst case scenario I manually create CFrames for each accessory that I have, and it’d be offset from the rig’s head by that CFrame. This would be really tedious to perfect though…

1 Like

Oh yeah, this would be insanely annoying to do. I wouldn’t even try this if it were a last resort.

Personally, I would create attachments in the accessory in question and then position the accessory to the character in such a way that the accessory’s attachment matches one on the character. This is what accessories normally when creating the weld between the accessory’s handle and the character, so I think this would be an appropriate approach if you just subtract the weld.

Another option, though this could get tedious as well, is to bring the rig out of the ViewportFrame. Once you do that, you add the accessory, anchor all BasePart descendants of the character, delete any created welds and then put the rig back in the ViewportFrame. If you end up doing this, consider a “reloading screen” (similar to what the website avatar page does) so users don’t watch the horror as their character disappears for a brief second and then comes back with a new accessory.

5 Likes