Only 1 mesh deleting

Hey there!

I am currently developing a game and having a bit of trouble, so i have a script that checks when a models “health” reaches 0 and when it does all mesh parts should be deleted but for some reason only 1 mesh gets deleted not all of them?

The Script:

-- This script is located within a proximity prompt that is in a part which is inside of the model, this is also a server script

health:GetPropertyChangedSignal("Value"):Connect(function()
	local clone = chunk:Clone()
	clone.Parent = repStore
	clone.Mine.ProximityPrompt.MaxActivationDistance = 10
	local child = chunk:GetChildren() -- Not looping through all children?
	for i, v in pairs(child) do -- Not looping through all children?
		if v:IsA("MeshPart") then
			v:Destroy() -- Only deletes 1?
			wait(10)
			clone.Parent = game.Workspace
			chunk:Destroy()
		end
	end
end)

Thanks for the help! :slight_smile:

1 Like

According to your code, it’ll only delete a mesh 10 seconds after deleting the previous mesh. I’m not sure if that’s what you want. If it isn’t, check the code below:

health:GetPropertyChangedSignal("Value"):Connect(function()
	local clone = chunk:Clone()
	clone.Parent = repStore
	clone.Mine.ProximityPrompt.MaxActivationDistance = 10
	for i, v in pairs(chunk:GetDescendants()) do -- Not looping through all children?
		if v:IsA("MeshPart") then
			v:Destroy() 
		end
	end

    task.wait(10)
    clone.Parent = game.Workspace
    chunk:Destroy()
end)
1 Like