Hats don't attach properly to character in ViewportFrame

I’m trying to make a dialogue system. I want an icon on the right showing the NPC.
I did this by copying the face, colors and the hats onto a character in a ViewportFrame.
The problem is the hats. They won’t attach properly onto the ViewportFrame character.
I have no clue why or how to fix this.

This is the icon
image

This is the actual character
image

The hat does indeed get copied, but it stays in the exact same position of the actual character
image
image

This is a portion of the script, you dont need to know the full script, but if you want you can ask me for it in the comments.
Local Script:

--<Viewmodel>--
person.Head.Face.Texture = npc.Head.Face.Texture
if npc:FindFirstChild("Body Colors") then
	npc["Body Colors"]:Clone().Parent = person
end
for _, accesories in pairs(npc:GetChildren()) do
	if accesories:IsA("Accessory") then
	    local hat = accesories:Clone()
		person.Humanoid:AddAccessory(hat)
	end
end

I would greatly appreciate some help! Thanks!

Did you check the ClassName value? Alot of the time hats would be called “HatAccessory” instead of just “Accessory” for some reason

Might also have something to do with its currentcamera

The ClassName value is “Accessory”

Also if you’re cloning an entire accessory item and using :AddAccessory() it may not work, its usually used for mesh parts, have you tried using humanoid descriptions instead?

Try to put the parent of the Character to Workspace and wait(.01) then put it back to the viewport frame.

Humanoid descriptions are much easier to use you can create one and set its HatAccessory to whatever the Model ID is… Heres an example

local NPC_Humanoid = person.Humanoid
local humDesc = NPC_Humanoid:GetAppliedDescription()

humDesc.HatAccessory = 123456789 --ID of your accessory model that you have uploaded
NPC_Humanoid:ApplyDescription()

This appears to also not work.
Since I used a local script, and ApplyDescription() only works on the server I had to use a remote event. It also did not have the hat on.

Made the character look funny, but still didn’t get the hat.
image

I am currently experiencing this same issue.

Sorry for the SUPER late response, but I managed to fix it!
You have to apply the accessory in workspace before moving it to the ViewPort frame.
you can do this:

npc.Parent = workspace
-- you can add accessory here
wait(0.1)
npc.Parent = viewport
-- or you can add them here, it works for me.
5 Likes