function RigTypes.getAttachments(l,O)if O==Enum.HumanoidRigType.R6 then return RigTypes.getR6Attachments(l)elseif O==Enum.HumanoidRigType.R15 then return RigTypes.getR15Attachments(l)else return{}end end function RigTypes.getR6Attachments(l)local O=Instance.new("\065\116\116\097\099\104\109\101\110\116")O.Name="\082\097\103\100\111\108\108\082\105\103\104\116\076\101\103\065\116\116\097\099\104\109\101\110\116"O.Position=Vector3.new(0,1,0)O.Parent=l:FindFirstChild("\082\105\103\104\116 \076\101\103")local h=Instance.new("\065\116\116\097\099\104\109\101\110\116")h.Name="\082\097\103\100\111\108\108\076\101\102\116\076\101\103\065\116\116\097\099\104\109\101\110\116"h.Position=Vector3.new(0,1,0)h.Parent=l:FindFirstChild("\076\101\102\116 \076\101\103")local A=Instance.new("\065\116\116\097\099\104\109\101\110\116")A.Name="\082\097\103\100\111\108\108\084\111\114\115\111\076\101\102\116\065\116\116\097\099\104\109\101\110\116"A.Position=Vector3.new(-0.5,-1,0)A.Parent=l:FindFirstChild("\084\111\114\115\111")local K=Instance.new("\065\116\116\097\099\104\109\101\110\116")K.Name="\082\097\103\100\111\108\108\084\111\114\115\111\082\105\103\104\116\065\116\116\097\099\104\109\101\110\116"K.Position=Vector3.new(.5,-1,0)K.Parent=l:FindFirstChild("\084\111\114\115\111")local Q=Instance.new("\065\116\116\097\099\104\109\101\110\116")Q.Name="\082\097\103\100\111\108\108\072\101\097\100\065\116\116\097\099\104\109\101\110\116"Q.Position=Vector3.new(0,-0.5,0)Q.Parent=l:FindFirstChild("\072\101\097\100")local f=Instance.new("\065\116\116\097\099\104\109\101\110\116")f.Name="\082\097\103\100\111\108\108\076\101\102\116\065\114\109\065\116\116\097\099\104\109\101\110\116"f.Position=Vector3.new(.3,1,0)f.Parent=l:FindFirstChild("\076\101\102\116 \065\114\109")local C=Instance.new("\065\116\116\097\099\104\109\101\110\116")C.Name="\082\097\103\100\111\108\108\082\105\103\104\116\065\114\109\065\116\116\097\099\104\109\101\110\116"C.Position=Vector3.new(-0.3,1,0)C.Parent=l:FindFirstChild("\082\105\103\104\116 \065\114\109")local V=find(l)return{Head=V({"\084\111\114\115\111";"\078\101\099\107\065\116\116\097\099\104\109\101\110\116"},{"\072\101\097\100";"\082\097\103\100\111\108\108\072\101\097\100\065\116\116\097\099\104\109\101\110\116"},R6_HEAD_LIMITS);["\076\101\102\116 \065\114\109"]=V({"\084\111\114\115\111","\076\101\102\116\067\111\108\108\097\114\065\116\116\097\099\104\109\101\110\116"},{"\076\101\102\116 \065\114\109";"\082\097\103\100\111\108\108\076\101\102\116\065\114\109\065\116\116\097\099\104\109\101\110\116"},R6_SHOULDER_LIMITS);["\082\105\103\104\116 \065\114\109"]=V({"\084\111\114\115\111";"\082\105\103\104\116\067\111\108\108\097\114\065\116\116\097\099\104\109\101\110\116"},{"\082\105\103\104\116 \065\114\109","\082\097\103\100\111\108\108\082\105\103\104\116\065\114\109\065\116\116\097\099\104\109\101\110\116"},R6_SHOULDER_LIMITS);["\076\101\102\116 \076\101\103"]=createJointData(A,h,R6_HIP_LIMITS);["\082\105\103\104\116 \076\101\103"]=createJointData(K,O,R6_HIP_LIMITS)}end function RigTypes.getR15Attachments(l)local O=find(l)return{Head=O({"\085\112\112\101\114\084\111\114\115\111","\078\101\099\107\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\072\101\097\100";"\078\101\099\107\082\105\103\065\116\116\097\099\104\109\101\110\116"},HEAD_LIMITS),LowerTorso=O({"\085\112\112\101\114\084\111\114\115\111","\087\097\105\115\116\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\076\111\119\101\114\084\111\114\115\111","\082\111\111\116\082\105\103\065\116\116\097\099\104\109\101\110\116"},LOWER_TORSO_LIMITS);LeftUpperArm=O({"\085\112\112\101\114\084\111\114\115\111","\076\101\102\116\083\104\111\117\108\100\101\114\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\076\101\102\116\085\112\112\101\114\065\114\109","\076\101\102\116\083\104\111\117\108\100\101\114\082\105\103\065\116\116\097\099\104\109\101\110\116"},SHOULDER_LIMITS);LeftLowerArm=O({"\076\101\102\116\085\112\112\101\114\065\114\109","\076\101\102\116\069\108\098\111\119\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\076\101\102\116\076\111\119\101\114\065\114\109";"\076\101\102\116\069\108\098\111\119\082\105\103\065\116\116\097\099\104\109\101\110\116"},ELBOW_LIMITS);LeftHand=O({"\076\101\102\116\076\111\119\101\114\065\114\109";"\076\101\102\116\087\114\105\115\116\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\076\101\102\116\072\097\110\100";"\076\101\102\116\087\114\105\115\116\082\105\103\065\116\116\097\099\104\109\101\110\116"},HAND_FOOT_LIMITS),RightUpperArm=O({"\085\112\112\101\114\084\111\114\115\111";"\082\105\103\104\116\083\104\111\117\108\100\101\114\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\082\105\103\104\116\085\112\112\101\114\065\114\109","\082\105\103\104\116\083\104\111\117\108\100\101\114\082\105\103\065\116\116\097\099\104\109\101\110\116"},SHOULDER_LIMITS),RightLowerArm=O({"\082\105\103\104\116\085\112\112\101\114\065\114\109";"\082\105\103\104\116\069\108\098\111\119\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\082\105\103\104\116\076\111\119\101\114\065\114\109";"\082\105\103\104\116\069\108\098\111\119\082\105\103\065\116\116\097\099\104\109\101\110\116"},ELBOW_LIMITS);RightHand=O({"\082\105\103\104\116\076\111\119\101\114\065\114\109";"\082\105\103\104\116\087\114\105\115\116\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\082\105\103\104\116\072\097\110\100","\082\105\103\104\116\087\114\105\115\116\082\105\103\065\116\116\097\099\104\109\101\110\116"},HAND_FOOT_LIMITS);LeftUpperLeg=O({"\076\111\119\101\114\084\111\114\115\111","\076\101\102\116\072\105\112\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\076\101\102\116\085\112\112\101\114\076\101\103";"\076\101\102\116\072\105\112\082\105\103\065\116\116\097\099\104\109\101\110\116"},HIP_LIMITS);LeftLowerLeg=O({"\076\101\102\116\085\112\112\101\114\076\101\103";"\076\101\102\116\075\110\101\101\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\076\101\102\116\076\111\119\101\114\076\101\103";"\076\101\102\116\075\110\101\101\082\105\103\065\116\116\097\099\104\109\101\110\116"},KNEE_LIMITS);LeftFoot=O({"\076\101\102\116\076\111\119\101\114\076\101\103";"\076\101\102\116\065\110\107\108\101\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\076\101\102\116\070\111\111\116","\076\101\102\116\065\110\107\108\101\082\105\103\065\116\116\097\099\104\109\101\110\116"},HAND_FOOT_LIMITS);RightUpperLeg=O({"\076\111\119\101\114\084\111\114\115\111","\082\105\103\104\116\072\105\112\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\082\105\103\104\116\085\112\112\101\114\076\101\103","\082\105\103\104\116\072\105\112\082\105\103\065\116\116\097\099\104\109\101\110\116"},HIP_LIMITS);RightLowerLeg=O({"\082\105\103\104\116\085\112\112\101\114\076\101\103","\082\105\103\104\116\075\110\101\101\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\082\105\103\104\116\076\111\119\101\114\076\101\103";"\082\105\103\104\116\075\110\101\101\082\105\103\065\116\116\097\099\104\109\101\110\116"},KNEE_LIMITS),RightFoot=O({"\082\105\103\104\116\076\111\119\101\114\076\101\103";"\082\105\103\104\116\065\110\107\108\101\082\105\103\065\116\116\097\099\104\109\101\110\116"},{"\082\105\103\104\116\070\111\111\116";"\082\105\103\104\116\065\110\107\108\101\082\105\103\065\116\116\097\099\104\109\101\110\116"},HAND_FOOT_LIMITS)}end function RigTypes.getR6NoCollisions(l)local O={}local function h(h)local A=l:FindFirstChild(h[1])local K=l:FindFirstChild(h[2])if A and K then table.insert(O,{A,K})end end h({"\072\101\097\100","\084\111\114\115\111"})h({"\076\101\102\116 \065\114\109";"\084\111\114\115\111"})h({"\082\105\103\104\116 \065\114\109";"\084\111\114\115\111"})h({"\076\101\102\116 \076\101\103";"\084\111\114\115\111"})h({"\082\105\103\104\116 \076\101\103";"\084\111\114\115\111"})h({"\076\101\102\116 \076\101\103","\082\105\103\104\116 \076\101\103"})return O end function RigTypes.getR15NoCollisions(l)local O={}local function h(h)local A=l:FindFirstChild(h[1])local K=l:FindFirstChild(h[2])if A and K then table.insert(O,{A;K})end end h({"\072\101\097\100","\085\112\112\101\114\084\111\114\115\111"})h({"\085\112\112\101\114\084\111\114\115\111";"\076\111\119\101\114\084\111\114\115\111"})h({"\085\112\112\101\114\084\111\114\115\111";"\076\101\102\116\085\112\112\101\114\065\114\109"})h({"\076\111\119\101\114\084\111\114\115\111","\076\101\102\116\085\112\112\101\114\065\114\109"})h({"\076\101\102\116\085\112\112\101\114\065\114\109";"\076\101\102\116\076\111\119\101\114\065\114\109"})h({"\076\101\102\116\076\111\119\101\114\065\114\109","\076\101\102\116\072\097\110\100"})h({"\076\101\102\116\085\112\112\101\114\065\114\109","\076\101\102\116\072\097\110\100"})h({"\085\112\112\101\114\084\111\114\115\111","\082\105\103\104\116\085\112\112\101\114\065\114\109"})h({"\076\111\119\101\114\084\111\114\115\111";"\082\105\103\104\116\085\112\112\101\114\065\114\109"})h({"\082\105\103\104\116\085\112\112\101\114\065\114\109";"\082\105\103\104\116\076\111\119\101\114\065\114\109"})h({"\082\105\103\104\116\076\111\119\101\114\065\114\109";"\082\105\103\104\116\072\097\110\100"})h({"\082\105\103\104\116\085\112\112\101\114\065\114\109";"\082\105\103\104\116\072\097\110\100"})h({"\076\101\102\116\085\112\112\101\114\076\101\103","\082\105\103\104\116\085\112\112\101\114\076\101\103"})h({"\085\112\112\101\114\084\111\114\115\111","\082\105\103\104\116\085\112\112\101\114\076\101\103"})h({"\076\111\119\101\114\084\111\114\115\111","\082\105\103\104\116\085\112\112\101\114\076\101\103"})h({"\082\105\103\104\116\085\112\112\101\114\076\101\103";"\082\105\103\104\116\076\111\119\101\114\076\101\103"})h({"\082\105\103\104\116\076\111\119\101\114\076\101\103","\082\105\103\104\116\070\111\111\116"})h({"\082\105\103\104\116\085\112\112\101\114\076\101\103","\082\105\103\104\116\070\111\111\116"})h({"\085\112\112\101\114\084\111\114\115\111";"\076\101\102\116\085\112\112\101\114\076\101\103"})h({"\076\111\119\101\114\084\111\114\115\111","\076\101\102\116\085\112\112\101\114\076\101\103"})h({"\076\101\102\116\085\112\112\101\114\076\101\103";"\076\101\102\116\076\111\119\101\114\076\101\103"})h({"\076\101\102\116\076\111\119\101\114\076\101\103","\076\101\102\116\070\111\111\116"})h({"\076\101\102\116\085\112\112\101\114\076\101\103","\076\101\102\116\070\111\111\116"})h({"\085\112\112\101\114\084\111\114\115\111";"\076\101\102\116\076\111\119\101\114\076\101\103"})h({"\085\112\112\101\114\084\111\114\115\111";"\082\105\103\104\116\076\111\119\101\114\076\101\103"})h({"\076\111\119\101\114\084\111\114\115\111","\076\101\102\116\076\111\119\101\114\076\101\103"})h({"\076\111\119\101\114\084\111\114\115\111";"\082\105\103\104\116\076\111\119\101\114\076\101\103"})h({"\085\112\112\101\114\084\111\114\115\111";"\076\101\102\116\076\111\119\101\114\065\114\109"})h({"\085\112\112\101\114\084\111\114\115\111","\082\105\103\104\116\076\111\119\101\114\065\114\109"})local A=l:FindFirstChild("\085\112\112\101\114\084\111\114\115\111")if A and A.Size.x<=1.5 then h({"\072\101\097\100";"\076\101\102\116\085\112\112\101\114\065\114\109"})h({"\072\101\097\100","\082\105\103\104\116\085\112\112\101\114\065\114\109"})end return O end return RigTypes
-- Get list of attachments to make ballsocketconstraints between:
function RigTypes.getAttachments(model, rigType)
	if rigType == Enum.HumanoidRigType.R6 then
		return RigTypes.getR6Attachments(model)
	elseif rigType == Enum.HumanoidRigType.R15 then
		return RigTypes.getR15Attachments(model)
	else
		return {}
	end
end

function RigTypes.getR6Attachments(model)
	local rightLegAttachment = Instance.new("Attachment")
	rightLegAttachment.Name = "RagdollRightLegAttachment"
	rightLegAttachment.Position = Vector3.new(0, 1, 0)
	rightLegAttachment.Parent = model:FindFirstChild("Right Leg")

	local leftLegAttachment = Instance.new("Attachment")
	leftLegAttachment.Name = "RagdollLeftLegAttachment"
	leftLegAttachment.Position = Vector3.new(0, 1, 0)
	leftLegAttachment.Parent = model:FindFirstChild("Left Leg")

	local torsoLeftAttachment = Instance.new("Attachment")
	torsoLeftAttachment.Name = "RagdollTorsoLeftAttachment"
	torsoLeftAttachment.Position = Vector3.new(-0.5, -1, 0)
	torsoLeftAttachment.Parent = model:FindFirstChild("Torso")

	local torsoRightAttachment = Instance.new("Attachment")
	torsoRightAttachment.Name = "RagdollTorsoRightAttachment"
	torsoRightAttachment.Position = Vector3.new(0.5, -1, 0)
	torsoRightAttachment.Parent = model:FindFirstChild("Torso")

	local headAttachment = Instance.new("Attachment")
	headAttachment.Name = "RagdollHeadAttachment"
	headAttachment.Position = Vector3.new(0, -0.5, 0)
	headAttachment.Parent = model:FindFirstChild("Head")

	local leftArmAttachment = Instance.new("Attachment")
	leftArmAttachment.Name = "RagdollLeftArmAttachment"
	leftArmAttachment.Position = Vector3.new(0.3, 1, 0)
	leftArmAttachment.Parent = model:FindFirstChild("Left Arm")

	local ragdollRightArmAttachment = Instance.new("Attachment")
	ragdollRightArmAttachment.Name = "RagdollRightArmAttachment"
	ragdollRightArmAttachment.Position = Vector3.new(-0.3, 1, 0)
	ragdollRightArmAttachment.Parent = model:FindFirstChild("Right Arm")

	local query = find(model)

	return {
		Head = query({ "Torso", "NeckAttachment" }, { "Head", "RagdollHeadAttachment" }, R6_HEAD_LIMITS),
		["Left Arm"] = query(
			{ "Torso", "LeftCollarAttachment" },
			{ "Left Arm", "RagdollLeftArmAttachment" },
			R6_SHOULDER_LIMITS
		),
		["Right Arm"] = query(
			{ "Torso", "RightCollarAttachment" },
			{ "Right Arm", "RagdollRightArmAttachment" },
			R6_SHOULDER_LIMITS
		),
		["Left Leg"] = createJointData(torsoLeftAttachment, leftLegAttachment, R6_HIP_LIMITS),
		["Right Leg"] = createJointData(torsoRightAttachment, rightLegAttachment, R6_HIP_LIMITS),
	}
end

function RigTypes.getR15Attachments(model)
	local query = find(model)

	return {
		Head = query({ "UpperTorso", "NeckRigAttachment" }, { "Head", "NeckRigAttachment" }, HEAD_LIMITS),

		LowerTorso = query(
			{ "UpperTorso", "WaistRigAttachment" },
			{ "LowerTorso", "RootRigAttachment" },
			LOWER_TORSO_LIMITS
		),

		LeftUpperArm = query(
			{ "UpperTorso", "LeftShoulderRigAttachment" },
			{ "LeftUpperArm", "LeftShoulderRigAttachment" },
			SHOULDER_LIMITS
		),
		LeftLowerArm = query(
			{ "LeftUpperArm", "LeftElbowRigAttachment" },
			{ "LeftLowerArm", "LeftElbowRigAttachment" },
			ELBOW_LIMITS
		),
		LeftHand = query(
			{ "LeftLowerArm", "LeftWristRigAttachment" },
			{ "LeftHand", "LeftWristRigAttachment" },
			HAND_FOOT_LIMITS
		),

		RightUpperArm = query(
			{ "UpperTorso", "RightShoulderRigAttachment" },
			{ "RightUpperArm", "RightShoulderRigAttachment" },
			SHOULDER_LIMITS
		),
		RightLowerArm = query(
			{ "RightUpperArm", "RightElbowRigAttachment" },
			{ "RightLowerArm", "RightElbowRigAttachment" },
			ELBOW_LIMITS
		),
		RightHand = query(
			{ "RightLowerArm", "RightWristRigAttachment" },
			{ "RightHand", "RightWristRigAttachment" },
			HAND_FOOT_LIMITS
		),

		LeftUpperLeg = query(
			{ "LowerTorso", "LeftHipRigAttachment" },
			{ "LeftUpperLeg", "LeftHipRigAttachment" },
			HIP_LIMITS
		),
		LeftLowerLeg = query(
			{ "LeftUpperLeg", "LeftKneeRigAttachment" },
			{ "LeftLowerLeg", "LeftKneeRigAttachment" },
			KNEE_LIMITS
		),
		LeftFoot = query(
			{ "LeftLowerLeg", "LeftAnkleRigAttachment" },
			{ "LeftFoot", "LeftAnkleRigAttachment" },
			HAND_FOOT_LIMITS
		),

		RightUpperLeg = query(
			{ "LowerTorso", "RightHipRigAttachment" },
			{ "RightUpperLeg", "RightHipRigAttachment" },
			HIP_LIMITS
		),
		RightLowerLeg = query(
			{ "RightUpperLeg", "RightKneeRigAttachment" },
			{ "RightLowerLeg", "RightKneeRigAttachment" },
			KNEE_LIMITS
		),
		RightFoot = query(
			{ "RightLowerLeg", "RightAnkleRigAttachment" },
			{ "RightFoot", "RightAnkleRigAttachment" },
			HAND_FOOT_LIMITS
		),
	}
end

function RigTypes.getR6NoCollisions(model)
	local list = {}

	local function addPair(pair)
		local part0 = model:FindFirstChild(pair[1])
		local part1 = model:FindFirstChild(pair[2])

		if part0 and part1 then
			table.insert(list, { part0, part1 })
		end
	end

	addPair({ "Head", "Torso" })
	addPair({ "Left Arm", "Torso" })
	addPair({ "Right Arm", "Torso" })
	addPair({ "Left Leg", "Torso" })
	addPair({ "Right Leg", "Torso" })

	addPair({ "Left Leg", "Right Leg" })

	return list
end

function RigTypes.getR15NoCollisions(model)
	local list = {}

	local function addPair(pair)
		local part0 = model:FindFirstChild(pair[1])
		local part1 = model:FindFirstChild(pair[2])

		if part0 and part1 then
			table.insert(list, { part0, part1 })
		end
	end

	addPair({ "Head", "UpperTorso" })
	addPair({ "UpperTorso", "LowerTorso" })

	addPair({ "UpperTorso", "LeftUpperArm" })
	addPair({ "LowerTorso", "LeftUpperArm" })
	addPair({ "LeftUpperArm", "LeftLowerArm" })
	addPair({ "LeftLowerArm", "LeftHand" })
	addPair({ "LeftUpperArm", "LeftHand" })

	addPair({ "UpperTorso", "RightUpperArm" })
	addPair({ "LowerTorso", "RightUpperArm" })
	addPair({ "RightUpperArm", "RightLowerArm" })
	addPair({ "RightLowerArm", "RightHand" })
	addPair({ "RightUpperArm", "RightHand" })

	addPair({ "LeftUpperLeg", "RightUpperLeg" })

	addPair({ "UpperTorso", "RightUpperLeg" })
	addPair({ "LowerTorso", "RightUpperLeg" })
	addPair({ "RightUpperLeg", "RightLowerLeg" })
	addPair({ "RightLowerLeg", "RightFoot" })
	addPair({ "RightUpperLeg", "RightFoot" })

	addPair({ "UpperTorso", "LeftUpperLeg" })
	addPair({ "LowerTorso", "LeftUpperLeg" })
	addPair({ "LeftUpperLeg", "LeftLowerLeg" })
	addPair({ "LeftLowerLeg", "LeftFoot" })
	addPair({ "LeftUpperLeg", "LeftFoot" })

	-- Support weird R15 rigs
	addPair({ "UpperTorso", "LeftLowerLeg" })
	addPair({ "UpperTorso", "RightLowerLeg" })
	addPair({ "LowerTorso", "LeftLowerLeg" })
	addPair({ "LowerTorso", "RightLowerLeg" })

	addPair({ "UpperTorso", "LeftLowerArm" })
	addPair({ "UpperTorso", "RightLowerArm" })

	local upperTorso = model:FindFirstChild("UpperTorso")
	if upperTorso and upperTorso.Size.x <= 1.5 then
		addPair({ "Head", "LeftUpperArm" })
		addPair({ "Head", "RightUpperArm" })
	end

	return list
end

return RigTypes
