local s=workspace.CurrentCamera if s.CameraSubject==character.Humanoid then s.CameraSubject=character.UpperTorso end character.HumanoidRootPart.Anchored=true character.HumanoidRootPart.CanCollide=false recurse(character,function(s,k)if k:IsA("\065\116\116\097\099\104\109\101\110\116")then k.Axis=Vector3.new(0,1,0)k.SecondaryAxis=Vector3.new(0,0,1)k.Rotation=Vector3.new(0,0,0)end end)for s,k in next,character:GetChildren()do if k:IsA("\065\099\099\111\117\116\114\101\109\101\110\116")then for s,k in next,k:GetChildren()do if k:IsA("\066\097\115\101\080\097\114\116")then local s=k:FindFirstChildOfClass("\065\116\116\097\099\104\109\101\110\116")local r=getAttachment0(s.Name)if r and s then local k=Instance.new("\072\105\110\103\101\067\111\110\115\116\114\097\105\110\116")k.Attachment0=r k.Attachment1=s k.LimitsEnabled=true k.UpperAngle=0 k.LowerAngle=0 k.Parent=character end end end end end ragdollJoint(character.LowerTorso,character.UpperTorso,"\087\097\105\115\116","\066\097\108\108\083\111\099\107\101\116",{{"\076\105\109\105\116\115\069\110\097\098\108\101\100";true},{"\085\112\112\101\114\065\110\103\108\101";5}})local k={{"\076\105\109\105\116\115\069\110\097\098\108\101\100",true},{"\085\112\112\101\114\065\110\103\108\101",0},{"\076\111\119\101\114\065\110\103\108\101";0}}ragdollJoint(character.LeftLowerArm,character.LeftHand,"\076\101\102\116\087\114\105\115\116","\072\105\110\103\101",k)ragdollJoint(character.RightLowerArm,character.RightHand,"\082\105\103\104\116\087\114\105\115\116","\072\105\110\103\101",k)local r={{"\076\105\109\105\116\115\069\110\097\098\108\101\100";true};{"\085\112\112\101\114\065\110\103\108\101",0};{"\076\111\119\101\114\065\110\103\108\101";-75}}ragdollJoint(character.LeftUpperLeg,character.LeftLowerLeg,"\076\101\102\116\075\110\101\101","\072\105\110\103\101",r)ragdollJoint(character.RightUpperLeg,character.RightLowerLeg,"\082\105\103\104\116\075\110\101\101","\072\105\110\103\101",r)local z={{"\076\105\109\105\116\115\069\110\097\098\108\101\100",true},{"\085\112\112\101\114\065\110\103\108\101",15};{"\076\111\119\101\114\065\110\103\108\101";-45}}ragdollJoint(character.LeftLowerLeg,character.LeftFoot,"\076\101\102\116\065\110\107\108\101","\072\105\110\103\101",z)ragdollJoint(character.RightLowerLeg,character.RightFoot,"\082\105\103\104\116\065\110\107\108\101","\072\105\110\103\101",z)ragdollJoint(character.UpperTorso,character.LeftUpperArm,"\076\101\102\116\083\104\111\117\108\100\101\114","\066\097\108\108\083\111\099\107\101\116")ragdollJoint(character.LeftUpperArm,character.LeftLowerArm,"\076\101\102\116\069\108\098\111\119","\066\097\108\108\083\111\099\107\101\116")ragdollJoint(character.UpperTorso,character.RightUpperArm,"\082\105\103\104\116\083\104\111\117\108\100\101\114","\066\097\108\108\083\111\099\107\101\116")ragdollJoint(character.RightUpperArm,character.RightLowerArm,"\082\105\103\104\116\069\108\098\111\119","\066\097\108\108\083\111\099\107\101\116")ragdollJoint(character.LowerTorso,character.LeftUpperLeg,"\076\101\102\116\072\105\112","\066\097\108\108\083\111\099\107\101\116")ragdollJoint(character.LowerTorso,character.RightUpperLeg,"\082\105\103\104\116\072\105\112","\066\097\108\108\083\111\099\107\101\116")

	local camera = workspace.CurrentCamera
	if camera.CameraSubject == character.Humanoid then--If developer isn't controlling camera
		camera.CameraSubject = character.UpperTorso
	end

	--Make it so ragdoll can't collide with invisible HRP, but don't let HRP fall through map and be destroyed in process	
	character.HumanoidRootPart.Anchored = true
	character.HumanoidRootPart.CanCollide = false

	--Helps to fix constraint spasms
	recurse(character, function(_,v)
		if v:IsA("Attachment") then
			v.Axis = Vector3.new(0, 1, 0)
			v.SecondaryAxis = Vector3.new(0, 0, 1)
			v.Rotation = Vector3.new(0, 0, 0)
		end
	end)
	
	--Re-attach hats
	for _,child in next,character:GetChildren() do
		if child:IsA("Accoutrement") then
			--Loop through all parts instead of only checking for one to be forwards-compatible in the event
			--ROBLOX implements multi-part accessories
			for _,part in next,child:GetChildren() do
				if part:IsA("BasePart") then
					local attachment1 = part:FindFirstChildOfClass("Attachment")
					local attachment0 = getAttachment0(attachment1.Name)
					if attachment0 and attachment1 then
						--Shouldn't use constraints for this, but have to because of a ROBLOX idiosyncrasy where
						--joints connecting a character are perpetually deleted while the character is dead
						local constraint = Instance.new("HingeConstraint")
						constraint.Attachment0 = attachment0
						constraint.Attachment1 = attachment1
						constraint.LimitsEnabled = true
						constraint.UpperAngle = 0 --Simulate weld by making it difficult for constraint to move
						constraint.LowerAngle = 0
						constraint.Parent = character
					end
				end
			end
		end
	end
	
	ragdollJoint(character.LowerTorso, character.UpperTorso, "Waist", "BallSocket", {
		{"LimitsEnabled",true};
		{"UpperAngle",5};
	})
	--[[ragdollJoint(character.UpperTorso, character.Head, "Neck", "BallSocket", {
		{"LimitsEnabled",true};
		{"UpperAngle",15};
	})]]
	
	local handProperties = {
		{"LimitsEnabled", true};
		{"UpperAngle",0};
		{"LowerAngle",0};
	}
	ragdollJoint(character.LeftLowerArm, character.LeftHand, "LeftWrist", "Hinge", handProperties)
	ragdollJoint(character.RightLowerArm, character.RightHand, "RightWrist", "Hinge", handProperties)
	
	local shinProperties = {
		{"LimitsEnabled", true};
		{"UpperAngle", 0};
		{"LowerAngle", -75};
	}
	ragdollJoint(character.LeftUpperLeg, character.LeftLowerLeg, "LeftKnee", "Hinge", shinProperties)
	ragdollJoint(character.RightUpperLeg, character.RightLowerLeg, "RightKnee", "Hinge", shinProperties)
	
	local footProperties = {
		{"LimitsEnabled", true};
		{"UpperAngle", 15};
		{"LowerAngle", -45};
	}
	ragdollJoint(character.LeftLowerLeg, character.LeftFoot, "LeftAnkle", "Hinge", footProperties)
	ragdollJoint(character.RightLowerLeg, character.RightFoot, "RightAnkle", "Hinge", footProperties)
	
	--TODO fix ability for socket to turn backwards whenn ConeConstraints are shipped
	ragdollJoint(character.UpperTorso, character.LeftUpperArm, "LeftShoulder", "BallSocket")
	ragdollJoint(character.LeftUpperArm, character.LeftLowerArm, "LeftElbow", "BallSocket")
	ragdollJoint(character.UpperTorso, character.RightUpperArm, "RightShoulder", "BallSocket")
	ragdollJoint(character.RightUpperArm, character.RightLowerArm, "RightElbow", "BallSocket")
	ragdollJoint(character.LowerTorso, character.LeftUpperLeg, "LeftHip", "BallSocket")
	ragdollJoint(character.LowerTorso, character.RightUpperLeg, "RightHip", "BallSocket")