How do I prevent weird Ragdoll Movements?

I’ve been attempting to make a ragdoll system that doesn’t require the humanoid to die
for the ragdoll to take place. This system works well, the only problem being that
the ragdoll has weird and janky movements that don’t happen with a normal
ragdoll-death one.

Here is a video of it occuring:
robloxapp-20210613-2106533.wmv (1.5 MB)

Here is the code of the ragdoll:

	local humanoid = character:FindFirstChild("Humanoid")
	local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
	
	visualRemotes.Ragdoll:FireAllClients(humanoid) -- This sets the client state to physics.
	humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	
	for index, motor in pairs(character:GetDescendants()) do
		if motor:IsA("Motor6D") then
			local a0, a1 = Instance.new("Attachment"), Instance.new("Attachment")
			a0.CFrame = motor.C0
			a1.CFrame = motor.C1
			a0.Name = "RagdollAttachment"
			a1.Name = "RagdollAttachment"
			a0.Parent = motor.Part0
			a1.Parent = motor.Part1

			local ballSocket = Instance.new("BallSocketConstraint")
			ballSocket.LimitsEnabled = true
			ballSocket.TwistLimitsEnabled = true
			ballSocket.Attachment0 = a0
			ballSocket.Attachment1 = a1
			ballSocket.Name = "RagdollSocket"
			ballSocket.Parent = motor.Part0
			
			motor.Parent.CanCollide = true
			motor.Enabled = false
		end
	end
	humanoidRootPart.CanCollide = false
	humanoid.RequiresNeck = false
	humanoid.Sit = true