How to Weld a Hat to an NPC?

Hello there, I just have a simple question on how to weld a hat to an NPC. Currently when my NPC moves at all it will just leave the hat behind.

Will it not work with a WeldConstraint?

(Sorry I haven’t done much NPC scripting before)

This might be helpful! Developer Wiki source

From my experiments, Hats need the Mesh, a Handle and an Attachment to work, then need to be added as an Accessory. In code I do it like this:

local skull = ServerStorage.Pickups.Disease		-- The "hat" is stored here. It's a skull to show a diseased player/NPC in this instance
function linkSkull(character)		-- "character" is the Player/NPC to attach the "hat" to
    local humanoid = character:WaitForChild("Humanoid")

    -- Create the Accessory.
    local disease = Instance.new("Accessory")
    disease.Name = "Disease"
	-- Create the Handle
	local handle = skull:Clone()
    handle.Name = "Handle"
    handle.Size = Vector3.new(1, 1, 1)
    handle.Parent = disease
	-- Create the Attachment to the Player/NPC     
    local faceFrontAttachment = Instance.new("Attachment")
    faceFrontAttachment.Name = "FaceFrontAttachment"
    faceFrontAttachment.Position = Vector3.new(0, 2, 0) 	 -- high Y value as the skull hovers over the players head
    faceFrontAttachment.Parent = handle
     
    -- Attach the Accessory to the humanoid.
    humanoid:AddAccessory(disease)
end
1 Like

I should have specified that the hat is NOT from the catalog, it is made up of parts.

I have been having the same problem with my own animations.

OK, so the screenshot below shows how the Disease “hat” is attached to the player/NPC
image
To replicate this:

  1. Add an Accessory to the NPC
  2. Add a 0.1 x 0.1 x 0.1 part under the Accessory and call it Handle. Position the Handle inside the NPC Head
  3. Add an Attachment under the Handle, name it HatAttachment
  4. Add a Weld under Handle, name it AccessoryWeld
  5. In AccessoryWeld, set Data > Part0 to Handle (from above)
  6. In AccessoryWeld, set Data > Part1 to Head (of NPC)
  7. Insert your collection of Parts as a Model under Handle. Position the Model relative to the Handle inside the NPC Head.

I can’t guarantee it will work for you, but that appears to be how it is constructed when you look at your own Player character in the Workspace. Have a look.

Let me know if it works or not.

Bruh I literally just said it wasn’t a hat from the catalog, but doesn’t matter now. I used weld constraints and it works now even tho the first time I tried it didn’t…

The response I gave is nothing to do with hats from the catalog, but the correct way to add a model made of parts as a hat. Bruh.

1 Like

Hello @Allein277! :wave:

It’s honestly so sad to see nobody finding the right thing for you. I have got answers for you to finish this topic.

this weld plugin helps. Try this. If it doesn’t work I don’t know.

Have a great day and hope it works! :love_you_gesture: :smiley: :wave: