Why is my hat/accessory not on my head

Basically The model/hat instead of going on my head its inside my head
So I tried to look up the problem but instead i got this script where now the hat instead
of being inside my head its perfectly where it has to be but upside down???

Images

With script
image

image

Without script just the attachment

image

image

Script

function weldAttachments(attach1, attach2)
local weld = Instance.new(“Weld”)
weld.Part0 = attach1.Parent
weld.Part1 = attach2.Parent
weld.C0 = attach1.CFrame
weld.C1 = attach2.CFrame
weld.Parent = attach1.Parent
return weld
end

local function buildWeld(weldName, parent, part0, part1, c0, c1)
local weld = Instance.new(“Weld”)
weld.Name = weldName
weld.Part0 = part0
weld.Part1 = part1
weld.C0 = c0
weld.C1 = c1
weld.Parent = parent
return weld
end

local function findFirstMatchingAttachment(model, name)
for _, child in pairs(model:GetChildren()) do
if child:IsA(“Attachment”) and child.Name == name then
return child
elseif not child:IsA(“Accoutrement”) and not child:IsA(“Tool”) then – Don’t look in hats or tools in the character
local foundAttachment = findFirstMatchingAttachment(child, name)
if foundAttachment then
return foundAttachment
end
end
end
end

function addAccoutrement(character, accoutrement)
accoutrement.Parent = character
local handle = accoutrement:FindFirstChild(“Handle”)
if handle then
local accoutrementAttachment = handle:FindFirstChildOfClass(“Attachment”)
if accoutrementAttachment then
local characterAttachment = findFirstMatchingAttachment(character, accoutrementAttachment.Name)
if characterAttachment then
weldAttachments(characterAttachment, accoutrementAttachment)
end
else
local head = character:FindFirstChild(“Head”)
if head then
local attachmentCFrame = CFrame.new(0, 0.5, 0)
local hatCFrame = accoutrement.AttachmentPoint
buildWeld(“HeadWeld”, head, head, handle, attachmentCFrame, hatCFrame)
end
end
end
end

1 Like

local attachmentCFrame = CFrame.new(0, 0.5, 0)

This line is moving the attachment up 0.5 studs. Move the attachment up 0.5 studs manually and it should be in the correct position.

1 Like

what do you mean by manually?..

1 Like

In the attachment change its CFrame on the Y axis to whatever it is + 0.5

move the attachment yourself. Remember up is down and down is up right is left and left is right.

1 Like

maybe try using

local attachmentCFrame = CFrame.new(0, -0.5, 0) 

it might work

Nope did not work
image

Accessories consisting of only one part will automatically snap attachments of the same name to each other. You should be adding an attachment named HatAttachment to the accessory’s handle and positioning it accordingly. The Humanoid will accordingly snap the attachments together and weld them. There is no need to do any scripting on your part. Also, LocalScripts do not run in Workspace.

2 Likes

I do not have a hat attachment how do i add one?

You add one by adding one.

Follow the arrows. Open up your insert menu, find attachment, insert it into the handle, rename it to HatAttachment, position it as you like, done. From there all you need to do is parent it to the character, ideally not with a LocalScript if you’re hoping for it to replicate.

@.above Should never be using a LocalScript for this use case anyway. OP already seems to be using that code in their original attempt but there’s no need for code to resolve this problem.