function buildRigFromAttachments(G,a)for t,d in pairs(a:GetChildren())do if d:IsA("\065\116\116\097\099\104\109\101\110\116")and string.find(d.Name,"\082\105\103\065\116\116\097\099\104\109\101\110\116")then for t,T in pairs(a.Parent:GetChildren())do if T~=a and T~=G then local G=T:FindFirstChild(d.Name)if G then buildJoint(d,G)buildRigFromAttachments(a,G.Parent)end end end end end end local function G(G,a)for G,t in pairs(G:GetChildren())do if t:IsA("\067\104\097\114\097\099\116\101\114\077\101\115\104")and t.BodyPart==a.BodyPart then return t end end return nil end

function buildRigFromAttachments(last, part)
	for _, attachment in pairs(part:GetChildren()) do
		if attachment:IsA("Attachment") and string.find(attachment.Name, "RigAttachment") then
			for _, sibling in pairs(part.Parent:GetChildren()) do
				if sibling ~= part and sibling ~= last then
					local matchingAttachment = sibling:FindFirstChild(attachment.Name)
					if matchingAttachment then
						buildJoint(attachment, matchingAttachment)
						-- Continue the recursive tree traversal building joints
						buildRigFromAttachments(part, matchingAttachment.Parent)
					end
				end
			end
		end
	end
end
 
local function getOldCharacterMesh(character, newCharacterMesh)
    for _, obj in pairs(character:GetChildren()) do
        if obj:IsA("CharacterMesh") and obj.BodyPart == newCharacterMesh.BodyPart then
            return obj
        end 
    end
    return nil
end
 