I am trying to make a ragdoll for a dinosaur. Currently i am using the BreakJointsOnDeath feature for it but it seems to be a little glitchy.. I was wondering if i could get some help.

the code:

local died
died = Humanoid.Died:Connect(function()
	local d = script.Parent:GetDescendants()
	for i=1,#d do
		local desc = d[i]
		if desc:IsA("Motor6D") then
			local socket = Instance.new("BallSocketConstraint")
			local at0 = Instance.new("Attachment",desc.part0)
			local at1 = Instance.new("Attachment",desc.part1)
			at0.Position = desc.part0.Position
			at1.Position = desc.part1.Position
				socket.Attachment0, socket.Attachment1 = at0, at1
				socket.Parent = desc.Parent
				desc:Destroy()
		end
	end
end)

what happens when i die: https://gyazo.com/807878f5544e3a1d0f1a2f0d304d90dc