-- Ragdoll

Humanoid.AutoRotate = false
local Descendants = Character:GetDescendants()
for i, obj in pairs(Descendants) do
	-- If the descendant is a k then replace it with a socket
	if obj:IsA('Motor6D') then
		-- totally didnt take most of this from a youtube video
		local Socket = Instance.new('BallSocketConstraint',obj.Parent)
		local a1 = Instance.new('Attachment',obj.Part0) or obj.Parent:FindFirstChild('Attachment')
		local a2 = Instance.new('Attachment',obj.Part1) or obj.Parent:FindFirstChild('Attachment')
		a1.CFrame = obj.C0
		a2.CFrame = obj.C1
		Socket.Attachment0 = a1
		Socket.Attachment1 = a2
		Socket.LimitsEnabled = true
		Socket.TwistLimitsEnabled = true
		obj:Destroy()
	end
	-- If the descendant is a weld, realign the position --
	if obj:IsA('Weld') then 
		local Weld = obj:Clone()
		Weld.Parent = obj.Parent
		obj:Destroy()
	end
	-- Make all parts collidable
	if obj.Parent == Character then
		if obj:IsA('Part') or obj:IsA('MeshPart') then
			obj.CanCollide = true
		end
	end
end
