Help on rag doll death thing

So I’m trying to make when you die it clones the body and it stays for awhile before it despawns
There are no errors, but it only clones the HumanoidRootPart into the model, and no other parts. Can someone help me fix this?

game:GetService('Players').PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			print(player.Name .. " has died!")
			local body = Instance.new('Model', workspace)
			for i, child in ipairs(character:GetChildren()) do
				if child.ClassName == 'Part' or child.ClassName == 'MeshPart' then
					child.Parent = body
					local clone = child:Clone()
					print(clone.Name)
					clone.Parent = body
					body.PrimaryPart = body:FindFirstChild("HumanoidRootPart")
					wait(120) -- How long it takes for the ragdoll body to dissapear
					-clone:Destroy()
				end
			end
		end)
	end)
end)

also how would I make the body actually rag doll?

1 Like

Idk if this can help but try to clone Child.Parent:Clone()

1 Like

Hmm I tried that but it just clones a model with the HumanoidRootPart in it.

1 Like

The problem is here, printing i,Child it prints “1 HumanoidRootPart”

1 Like

What does that do again?

1 Like
 for i,v in pairs (player.Character:GetDescendants()) do
 -- code
    end)

If this helped, mark as solution.

2 Likes

When I do that it still only clones the root part into the model, it now just has a bunch of sounds in it.

2 Likes

Instead of doing this,
just do

 if Child:IsA("BasePart") then      
  --code
  end
1 Like
game:GetService("Players").PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(Character)
		Character:WaitForChild("Humanoid").Died:Connect(function()
			print(player.Name .. " has died!")
			print(Character.Parent)
			local test = (Character:GetChildren())
			
			local testing = Instance.new("Model",workspace)
			for i = 1, #test do
				local child = test[i]
				print(child.Name)
				child:Clone()
				child.Parent = testing
			end
		end)
	end)
end)

This clones all, the only issue is this orange error but does not stop the script

image
Idk how to not get this sadly but hope it helps

1 Like