Script helping in pairs?

rock

	coroutine.wrap(function()
	for Index,Part in pairs(script.Parent:GetChildren()) do
		while wait() do
		local RandomPart = math.random(1,30)
		print(Part)
		if Part.ClassName == "Part" then
			if Part.Name == "Rock"..RandomPart then
				for c=0,-20,-.5 do
				Part.Position = Vector3.new(Part.Position.X,Part.Position.Y+c,Part.Position.Z)
				print(c)
				wait(.5)
			    end
			Part:Destroy()
		    end
		end
		end
	end
	end)()

Why only prints Rock29?

While loops yield. When you loop through every part you start a while loop on the first one:

for Index,Part in pairs(script.Parent:GetChildren()) do
		while wait() do
			--yields and only will print one part
        end
	end

This is preventing the for loop from looping through other parts.

To fix this, put the coroutine around the while loop

for Index,Part in pairs(script.Parent:GetChildren()) do
		coroutine.wrap(function()
			while wait() do
				
			end
		end)()
	end

Though this will cause some lag and there is a better way to do this.

Your while wait() do loop stops the outer for loop from ever advancing. You’re always stuck on the first iteration.

edit: Ninja’d