Need help with perma ragdoll

i have this ragdoll script thats meant to save the ragdoll when the player dies

it doesn’t ragdoll the old character

local Players = game:GetService("Players")

local function ragdollCharacter(char)
	for _, v in pairs(char:GetDescendants()) do
		if v:IsA("Motor6D") then
			local Attachment0, Attachment1 = Instance.new("Attachment"), Instance.new("Attachment")
			Attachment0.CFrame = v.C0
			Attachment1.CFrame = v.C1
			Attachment0.Parent = v.Part0
			Attachment1.Parent = v.Part1

			local BallSocketConstraint = Instance.new("BallSocketConstraint")
			BallSocketConstraint.Attachment0 = Attachment0
			BallSocketConstraint.Attachment1 = Attachment1
			BallSocketConstraint.Parent = v.Parent

			v:Destroy()
		end
	end
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		local oldCharacterClone = player.Character or player.CharacterAdded:Wait()
		Character.Humanoid.BreakJointsOnDeath = false
		Character.Archivable = true
		Character.Humanoid.Died:Connect(function()
			local ragdoll = Character:Clone()
			ragdoll.Parent = workspace
			ragdoll:WaitForChild("HumanoidRootPart").CanCollide = false
			ragdoll:WaitForChild("Head").CanCollide = true
			ragdollCharacter(ragdoll)
			Character:Remove()
		end)
	end)
end)

  • UPDATE
    i set the parent it sometimes ragdolls but the character flies up