Why is my main character getting deleted when cloning it then parenting it?

I am trying to make a system which makes a ghost of your character after you die.
In my code below you see my code which should be working, the issue is, the character is successfully cloning but is missing animations. Not only is it missing animations but the linked character to the player gets deleted. My code is not deleting it and I need the character to stay on the ground so another user can revive them with a ritual.

selfCatch = character.Humanoid.Died:Connect(function()
	Player.Character.Archivable = true -- To be able to clone
	local NewCharacter = Player.Character:Clone()
	NewCharacter.Humanoid.Health = NewCharacter.Humanoid.MaxHealth -- Heal so we do not get a dead character

	game.ReplicatedStorage.RagdollEvent:FireClient(Player, 'Ragdoll')
	Ragdoll.RagdollServer(character)
	
	--Player.Character.Archivable = false
	NewCharacter.Parent = game.Workspace -- Main character gets deleted
	Player.Character = NewCharacter -- Works good, missing animations though
	
	selfCatch:Disconnect()
end)

If you are wondering about the ragdoll, here would be the module I used from badcc which works successfully

When the character property is changed, the old character is automatically parented to nil. However, it’s not destroyed so you can still reparent it to workspace. To fix the animation problem, I believe you could clone the Animate local script from the old character to the new one.

selfCatch = character.Humanoid.Died:Connect(function()
	character.Archivable = true -- To be able to clone
	local NewCharacter = character:Clone()
	NewCharacter.Humanoid.Health = NewCharacter.Humanoid.MaxHealth -- Heal so we do not get a dead character
	game.ReplicatedStorage.RagdollEvent:FireClient(Player, 'Ragdoll')
	Ragdoll.RagdollServer(character)
	
	--Player.Character.Archivable = false
	NewCharacter.Parent = game.Workspace -- Main character gets deleted
	Player.Character = NewCharacter -- Works good, missing animations though
    character.Animate:Clone().Parent = NewCharacter
    character.Parent = workspace
	
	selfCatch:Disconnect()
end)
1 Like

Your solution worked perfectly just how I wanted it.
Thanks!

Just one more question, when I ragdoll the character then clone the Animate script into the new character, the character on the ground loses it’s animation and looks all frozen.

Video demonstrating the current result.

Edit:
I was thinking on anchoring the character when reached the ground. But then I need to make it so witches can carry the dead body.
Would there also be a way to play animations on a dead character?