I'm trying to make a script where I can remove one part per second but it's not working.
I tried doing this:
game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1)game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) game.Workspace.Part:remove Wait (1) end
But it didn't work so please help.
You could loop through the workspace in search for all children with the Name Part or ClassName BasePart.
Loops facilitate simultaneously working with descendants of models or instances. Using one in this context would reduce the amount of lines the used by your code, and is overall much more efficient.
local myTable = workspace:GetChildren() for index = 1, #myTable do -- 1 being the interval, and the table after the comma. -- now check if the part at `index`'s Name is equal to Part -- and also check that the part and `index` is a `BasePart` if myTable[index].Name == 'Part' and myTable[index]:IsA('BasePart') then myTable[index]:Destroy() -- call the destroy function of part at `index` wait(1) -- wait 1 second end end
If you want it to be an infinite check, you could always make it all under another loop, that would run infinitely, instead of based on the number of parts inside the table/model.
local myTable = workspace:GetChildren() while wait(1) do for index = 1, #myTable do -- 1 being the interval, and the table after the comma. -- now check if the part at `index`'s Name is equal to Part -- and also check that the part and `index` is a `BasePart` if myTable[index].Name == 'Part' and myTable[index]:IsA('BasePart') then myTable[index]:Destroy() -- call the destroy function of part at `index` end end end
Finally, you could make a function to run whenever called, so that all you'd have to do to clear the workspace of all parts is to call the function
local myTable = workspace:GetChildren() clearWorkspace = function() for index = 1, #myTable do -- 1 being the interval, and the table after the comma. -- now check if the part at `index`'s Name is equal to Part -- and also check that the part and `index` is a `BasePart` if myTable[index].Name == 'Part' and myTable[index]:IsA('BasePart') then myTable[index]:Destroy() -- call the destroy function of part at `index` wait(1) -- wait 1 second end end end clearWorkspace()
I know ImageLabel's script works but please read the following message: THERE IS A SIMPLER AND MORE EFFICIENT WAY TO SCRIPT THIS!
I can turn ImageLabel's 14 lined script into a 7 lined one.
for _,p in pairs(workspace:GetChildren()) do if p:IsA("BasePart") and p.Name == "Part" then p:Destroy() end wait(1) end
Hope this helps!
5 Lined version:
for _,p in pairs(workspace:GetChildren()) do if p:IsA("BasePart") and p.Name == "Part" then game:GetService("Debris"):AddItem(p, 1) end end