✓ Accepted answer
#Problem
Seems this does work, but the program is waiting 5 seconds in between destroying bricks.
Lower the yield on line 1 and you should be fine.
while true do wait()
print("Bye bye bricks")
local found = game.Workspace:FindFirstChild("Part")
if found then
game:GetService("Debris"):AddItem(found)
end
print("Cleaned up!")
end
#Revisions
Now, this code is functional, but it isn't efficient yet. There are some syntax changes that could be made:
while loops check a condition prior to executing code. Instead of having true in the conditional spot, you can put the wait function there.
- This loop is going to run forever, constantly checking for Parts even if there are none. You can either add a
break statement(which breaks loops) or you can put a compound conditional in the while loop. This would consist of the and statement, along with another conditional - being workspace:FindFirstChild("Part") to ensure the loop only runs while parts are in the workspace.
- With this low of a yield between iterations printing anything is going to spam your output. You should remove prints.
while wait() and workspace:FindFirstChild("Part") do
game:GetService("Debris"):AddItem(workspace.Part)
end
1 comment
Fix your code block