function RigTypes.getAttachments(Y,E)if E==Enum.HumanoidRigType.R6 then return RigTypes.getR6Attachments(Y)elseif E==Enum.HumanoidRigType.R15 then return RigTypes.getR15Attachments(Y)else return{}end end function RigTypes.getR6Attachments(Y)local E=Instance.new("\065\116\116\097\099\104\109\101\110\116")E.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"E.Position=Vector3.new(0,1,0)E.Parent=Y:FindFirstChild("\082\105\103\104\116 \076\101\103")local k=Instance.new("\065\116\116\097\099\104\109\101\110\116")k.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"k.Position=Vector3.new(0,1,0)k.Parent=Y:FindFirstChild("\076\101\102\116 \076\101\103")local L=Instance.new("\065\116\116\097\099\104\109\101\110\116")L.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"L.Position=Vector3.new(-0.5,-1,0)L.Parent=Y:FindFirstChild("\084\111\114\115\111")local n=Instance.new("\065\116\116\097\099\104\109\101\110\116")n.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"n.Position=Vector3.new(.5,-1,0)n.Parent=Y:FindFirstChild("\084\111\114\115\111")local s=Instance.new("\065\116\116\097\099\104\109\101\110\116")s.Name="\082\097\103\100\111\108\108\072\101\097\100\065\116\116\097\099\104\109\101\110\116"s.Position=Vector3.new(0,-0.5,0)s.Parent=Y:FindFirstChild("\072\101\097\100")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\065\114\109\065\116\116\097\099\104\109\101\110\116"h.Position=Vector3.new(.3,1,0)h.Parent=Y:FindFirstChild("\076\101\102\116 \065\114\109")local F=Instance.new("\065\116\116\097\099\104\109\101\110\116")F.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"F.Position=Vector3.new(-0.3,1,0)F.Parent=Y:FindFirstChild("\082\105\103\104\116 \065\114\109")local T=find(Y)return{Head=T({"\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"]=T({"\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"]=T({"\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(L,k,R6_HIP_LIMITS);["\082\105\103\104\116 \076\101\103"]=createJointData(n,E,R6_HIP_LIMITS)}end function RigTypes.getR15Attachments(Y)local E=find(Y)return{Head=E({"\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=E({"\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=E({"\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=E({"\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=E({"\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=E({"\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=E({"\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=E({"\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=E({"\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=E({"\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=E({"\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=E({"\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=E({"\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=E({"\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(Y)local E={}local function k(k)local L=Y:FindFirstChild(k[1])local n=Y:FindFirstChild(k[2])if L and n then table.insert(E,{L;n})end end k({"\072\101\097\100","\084\111\114\115\111"})k({"\076\101\102\116 \065\114\109","\084\111\114\115\111"})k({"\082\105\103\104\116 \065\114\109";"\084\111\114\115\111"})k({"\076\101\102\116 \076\101\103","\084\111\114\115\111"})k({"\082\105\103\104\116 \076\101\103";"\084\111\114\115\111"})k({"\076\101\102\116 \076\101\103","\082\105\103\104\116 \076\101\103"})return E end function RigTypes.getR15NoCollisions(Y)local E={}local function k(k)local L=Y:FindFirstChild(k[1])local n=Y:FindFirstChild(k[2])if L and n then table.insert(E,{L;n})end end k({"\072\101\097\100";"\085\112\112\101\114\084\111\114\115\111"})k({"\085\112\112\101\114\084\111\114\115\111","\076\111\119\101\114\084\111\114\115\111"})k({"\085\112\112\101\114\084\111\114\115\111","\076\101\102\116\085\112\112\101\114\065\114\109"})k({"\076\111\119\101\114\084\111\114\115\111","\076\101\102\116\085\112\112\101\114\065\114\109"})k({"\076\101\102\116\085\112\112\101\114\065\114\109";"\076\101\102\116\076\111\119\101\114\065\114\109"})k({"\076\101\102\116\076\111\119\101\114\065\114\109","\076\101\102\116\072\097\110\100"})k({"\076\101\102\116\085\112\112\101\114\065\114\109";"\076\101\102\116\072\097\110\100"})k({"\085\112\112\101\114\084\111\114\115\111";"\082\105\103\104\116\085\112\112\101\114\065\114\109"})k({"\076\111\119\101\114\084\111\114\115\111","\082\105\103\104\116\085\112\112\101\114\065\114\109"})k({"\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"})k({"\082\105\103\104\116\076\111\119\101\114\065\114\109","\082\105\103\104\116\072\097\110\100"})k({"\082\105\103\104\116\085\112\112\101\114\065\114\109";"\082\105\103\104\116\072\097\110\100"})k({"\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"})k({"\085\112\112\101\114\084\111\114\115\111","\082\105\103\104\116\085\112\112\101\114\076\101\103"})k({"\076\111\119\101\114\084\111\114\115\111";"\082\105\103\104\116\085\112\112\101\114\076\101\103"})k({"\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"})k({"\082\105\103\104\116\076\111\119\101\114\076\101\103","\082\105\103\104\116\070\111\111\116"})k({"\082\105\103\104\116\085\112\112\101\114\076\101\103","\082\105\103\104\116\070\111\111\116"})k({"\085\112\112\101\114\084\111\114\115\111";"\076\101\102\116\085\112\112\101\114\076\101\103"})k({"\076\111\119\101\114\084\111\114\115\111","\076\101\102\116\085\112\112\101\114\076\101\103"})k({"\076\101\102\116\085\112\112\101\114\076\101\103","\076\101\102\116\076\111\119\101\114\076\101\103"})k({"\076\101\102\116\076\111\119\101\114\076\101\103";"\076\101\102\116\070\111\111\116"})k({"\076\101\102\116\085\112\112\101\114\076\101\103","\076\101\102\116\070\111\111\116"})k({"\085\112\112\101\114\084\111\114\115\111","\076\101\102\116\076\111\119\101\114\076\101\103"})k({"\085\112\112\101\114\084\111\114\115\111";"\082\105\103\104\116\076\111\119\101\114\076\101\103"})k({"\076\111\119\101\114\084\111\114\115\111","\076\101\102\116\076\111\119\101\114\076\101\103"})k({"\076\111\119\101\114\084\111\114\115\111";"\082\105\103\104\116\076\111\119\101\114\076\101\103"})k({"\085\112\112\101\114\084\111\114\115\111","\076\101\102\116\076\111\119\101\114\065\114\109"})k({"\085\112\112\101\114\084\111\114\115\111","\082\105\103\104\116\076\111\119\101\114\065\114\109"})local L=Y:FindFirstChild("\085\112\112\101\114\084\111\114\115\111")if L and L.Size.x<=1.5 then k({"\072\101\097\100";"\076\101\102\116\085\112\112\101\114\065\114\109"})k({"\072\101\097\100";"\082\105\103\104\116\085\112\112\101\114\065\114\109"})end return E end return RigTypes

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
