Help with my Ragdoll script, why do I get "LeftElbow is not a valid member of MeshPart"?

I am trying to create a ragdoll on death, but now I am getting this error and I cant see where is the problem. It says "“LeftElbow is not a valid member of MeshPart” but, for me, it actually is a child of the part. The error says: “LeftElbow is not a valid member of MeshPart” in line indicated bellow with comment. Note: the error is on the first object iterated by the for loop.

Humanoid.Died:Connect(function()
	Shoulder.C1 = DownShoulderCF1
	Shoulder.C0 = DownShoulderCF0
	-- RAGDOLL
	local Clone = Instance.new("Model")
	for i, v in pairs (Character:GetDescendants()) do
		if v.Name == "Cape" then
			v:Destroy()
		elseif v:IsA("BasePart") or v:IsA("MeshPart") or v:IsA("UnionOperation") and v.Name ~= "HumanoidRootPart" then
			v:Clone().Parent = Clone
		end
	end
	for i, v in pairs(Clone:GetDescendants()) do
		if v:IsA("Motor6D") then
			local w = Instance.new("Attachment")
			w.Parent = v.Part0
			w.Position = v.C0.Position
			w.Name = v.Name
			local w2 = Instance.new("Attachment")
			w2.Parent = v.Part1
			w2.Position = v.C1.Position
			w2.Name = v.Name
			print("created:", w.Name, "in", w.Parent, w2.Name, "in", w2.Parent)
			v:Destroy()
		end
	end

	for i, v in pairs(Clone:GetDescendants()) do
		if v:IsA("Attachment") then
			if v.Name == "Neck" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.UpperTorso.Neck
				w.Attachment1 = Clone.Head.Neck
			elseif v.Name == "Waist" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.LowerTorso.Waist
				w.Attachment1 = Clone.UpperTorso.Waist
			elseif v.Name == "LeftShoulder" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.UpperTorso.LeftShoulder
				w.Attachment1 = Clone.LeftUpperArm.LeftShoulder
			elseif v.Name == "LeftElbow" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.LeftUpperArm.LeftElbow -- ERROR: LeftElbow is not a valid member of MeshPart
				w.Attachment1 = Clone.LeftLowerArm.LeftElbow
			elseif v.Name == "LeftWrist" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.LeftLowerArm.LeftWrist
				w.Attachment1 = Clone.LeftHand.LeftWrist
			elseif v.Name == "RightShoulder" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.UpperTorso.RightShoulder
				w.Attachment1 = Clone.RightUpperArm.RightShoulder
			elseif v.Name == "RightElbow" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.RightUpperArm.RightElbow
				w.Attachment1 = Clone.RightLowerArm.RightElbow
			elseif v.Name == "RightWrist" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.RightLowerArm.RightWrist
				w.Attachment1 = Clone.RightHand.RightWrist
			elseif v.Name == "LeftHip" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.LowerTorso.LeftHip
				w.Attachment1 = Clone.RightUpperLeg.LeftHip
			elseif v.Name == "LeftKnee" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.LeftUpperLeg.LeftKnee
				w.Attachment1 = Clone.LeftLowerLeg.LeftKnee
			elseif v.Name == "LeftAnkle" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.LeftLowerLeg.LeftAnkle
				w.Attachment1 = Clone.LeftFoot.LeftAnkle
			elseif v.Name == "RightHip" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.LowerTorso.RightHip
				w.Attachment1 = Clone.RightUpperLeg.RightHip
			elseif v.Name == "LeftKnee" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.RightUpperLeg.LeftKnee
				w.Attachment1 = Clone.RightLowerLeg.LeftKnee
			elseif v.Name == "LeftAnkle" then
				local w = Instance.new("BallSocketConstraint")
				w.Parent = v.Parent
				w.Attachment0 = Clone.RightLowerLeg.LeftAnkle
				w.Attachment1 = Clone.RightFoot.LeftAnkle
			end
		end
	end
	for i, v in pairs (Character:GetDescendants()) do
		if v:IsA("BasePart") or v:IsA("MeshPart") or v:IsA("UnionOperation")
		or v:IsA("Decal") then
			v.Transparency = 1
		elseif v:IsA("Tool") then
			v.Parent = workspace
		elseif v:IsA("Beam") then
			v.Transparency = NumberSequence.new(1)
		end
	end
	Clone.Name = "Corpse"
	for i, v in pairs(Clone) do
		v.Parent = Clone
	end
	Clone.Parent = workspace
end)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

I believe the error is quite obvious, there is no left elbow under meshpart or either the left elbow hasn’t loaded into the game yet.

Also what Rig are you using For R15 and R6 there is no LeftElbow Anyways, there is only a LeftElbowRigAttachment:

It is not the case of not loeaded yet cause is inside dead event. And im using R15. As you can read in the code, it delestes the LeftElbow joint and creates an attachment with this name.

i could just use rig attachment then :o

Sorry, but to be honest people don’t really like reading lots of lines of codes for free when they can zone in on the error message.

Yeah thats a pretty good idea. Have you looked at the community resource page? They already made working ones for R15 that work for all types of models, although I think the code can get pretty confusing (it automatically maps the attachment map so it would work with any type of Motor6d Rig except R6 for some reason due to how weird R6 is.

Damn I had swiched the names of the attachments, like: RIGHTUpperLeg.LEFTHip

Big oof, next time maybe try print debugging which is the simplest way to see the parent and the name of the “MeshPart” to make sure this doesn’t happen lol.

I already tried a lot of prints before e.e but i coudnt find anyway