Ragdoll script error: NeckRigAttachment is not a valid member of MeshPart "UpperTorso"

Hi,
I got a problem with a ragdoll script from this resource: R15 / Rthro Ragdolls
More precisely with this piece of code:

function buildAttachmentMap(character)
	local attachmentMap = {}
	
	character.UpperTorso:WaitForChild("NeckRigAttachment")
	for _,part in ipairs(character:GetChildren()) do
		if part:IsA("BasePart") then
			for _,attachment in ipairs(part:GetChildren()) do
				if attachment:IsA("Attachment") then
					local jointName = attachment.Name:match("^(.+)RigAttachment$")
					local joint = jointName and attachment.Parent:FindFirstChild(jointName) or nil
					
					if joint then
						attachmentMap[attachment.Name] = {
							Joint = joint,
							Attachment0=joint.Part0[attachment.Name];
							Attachment1=joint.Part1[attachment.Name];
						}
					end
				end
			end
		end
	end
	
	return attachmentMap
end

The error says:
NeckRigAttachment is not a valid member of MeshPart “UpperTorso”

And the error transfers to this line:
Attachment0=joint.Part0[attachment.Name];

I tried putting joint.Part0:WaitForChild(attachment.Name) but it said Infinite yield possible

Can someone help?

The NeckRigAttachment is not a valid member of MeshPart “UpperTorso” because it still hasn’t loaded.
You need to make sure it has loaded before trying to access it.

1 Like

I put a task.wait() before calling the module script but it breaks other parts of the script