How would I weld and position a hat to a players head?

Information

  1. I was wondering if I could somehow weld and position a hat to a players head? I have set up a function for cloning the hat and parenting it to the player, but I do not know how to weld and position it.

  2. As always I looked for answers on the web and devforum, but found nothing.:expressionless:

Please!
No entire scripts, and thanks to any help I can get!

4 Likes

I think the simplest way I learned to do this was by using the displacement of the head/hat attachments as a reference for C0 and C1 in a new weld:

local newWeld = Instance.new("Weld")
newWeld.C0 = hat.HatAttachment.CFrame
newWeld.C1 = head.HatAttachment.CFrame

It might be reversed, I don’t really know, but try that out.

4 Likes

ok thanks a lot I will let you know my feedback on what it does

3 Likes

so I updated your script to fit my needs, but it does not position on the head it shows up somewhere else

2 Likes

Try using Humanoid:AddAccessory(accessory), where accessory is your hat’s handle parented to the accessory object. Don’t forget about adding attachments to the hat.

5 Likes

well I am trying to add a model to the player not an accessory

1 Like

Aha, then you should do the same thing as @goldenstein64 previously mentioned.

To do this, weld all parts to a root of the hat. Then proceed doing the same thing. If it doesn’t work, the hat is missing attachments.

1 Like

Could you screenshot what the hierarchy of your hat model looks like? I’m theorizing you could just switch the model instance out for an accessory instance and it would still be the same hat, then you could just use @Operatik’s method.

1 Like

oh that is what I forgot guys the attachments, oops thanks for your help I am gonna test it out after I add the attachments

2 Likes

quick question how do you add an attachment, sorry

1 Like

nvm thanks for your help guys I am gonna test it out

1 Like

how many attachments would you need for the hat, would it depend on the amount of parts you have inside the model because it still does not attach to the face?

1 Like

You only need one attachment, which should correspond to one of the attachments on the head(or body).

Attachments can be added through the model tab, where you can create ropes, rods and other constraints.

1 Like

Just use accessories and attachments. Your hat is automatically positioned according to where the attachment is, as attachments are lined up. If you’re editing in Studio, changing the position of the attachment actually changes the position of the item being welded since accessory welds are rigid.

If you absolutely need to weld a model, the easiest way is to make an invisible clone of a limb, weld your parts to that and then weld the pseudo limb to the real limb. Use WeldConstraints. You use an extra instance but I prefer this over trying to figure out positions with math.

2 Likes
Here are some screenshots, sorry it took so long

GUI%20-%20Roblox%20Studio%2010_1_2019%206_07_18%20PM

GUI%20-%20Roblox%20Studio%2010_1_2019%206_07_39%20PM

1 Like

how would you connect a weld constraint to something using a script?

Literally just weld everything in your model and put it into your accessory. From there you can position it accordingly.

Keep in mind that I find accessories are often extremely glitchy when it comes to position. It’s not uncommon for your entire model to glitch out when parented to a character. This could be why you’re having unwanted results.

Edit: https://developer.roblox.com/en-us/api-reference/class/WeldConstraint

1 Like

Now I have this problem, 19:40:16.240 - Workspace.HatGiver:10: bad argument #3 to ‘Part0’ (Object expected, got CFrame)

Can you show me the code causing this error?

Here is my script:

game:GetService("Players").PlayerAdded:Connect(function(Player)
Player.CharacterAdded:Connect(function(plr)
game.ReplicatedStorage.Hat.OnServerEvent:Connect(function()
		local clone = game.ServerStorage.Handle:Clone()
		clone.Parent = plr
		local Part = game.ServerStorage.Handle.rootpart
		Part.Position = plr.Head.Position
		local newWeld = Instance.new("WeldConstraint")
		newWeld.Parent = workspace
newWeld.Part0 = Part.FaceCenterAttachment.CFrame
newWeld.Part1 = plr.Head.HatAttachment.CFrame
		print("Success")
end)
end)
end)