I'm trying to make all parts named "Galalaga" in the workspace be destroyed, but instead it clears my whole workspace
while wait(10) do
game.Workspace:ClearAllChildren("Galalaga")
end
I'm trying to make all parts named "Galalaga" in the workspace be destroyed, but instead it clears my whole workspace
while wait(10) do
game.Workspace:ClearAllChildren("Galalaga")
end
I am unsure if ClearAllChildren even has a parameter for a part that must be removed.
First, I'll say some things that you're doing incorrect, one being the fact the code doesn't function as you want it to. Now, the second problems you'll stumble upon is your code will continuously run and doesn't stop, I'll use a different loop which will not continue on forever.
A good way to remove the parts is a generic for loop that will check everything in the workspace for the name of "Galalaga" and destroy it. Lets start the loop by making a variable containing everything in the workspace then add it to our loop...
local Collect = game.Workspace:GetChildren()
for _, object in pairs(Collect) do
end
Now, object signifies something in the workspace, we want to see if that objects name is "Galalaga".
local Collect = game.Workspace:GetChildren()
for _, object in pairs(Collect) do
if object.Name == "Galalaga" then
end
end
Now, we need to cause the object to be destroyed.
local Collect = game.Workspace:GetChildren()
for _, object in pairs(Collect) do
if object.Name == "Galalaga" then
object:Destroy()
end
end
Please comment any questions you may have with what I have given... Above is the finished code.
This discussion is preserved as it was. New answers, comments, and votes are closed.
3 comments
To achieve what he wants you would have to check newly added children or put this in a loop. :)
I wasn't sure if he wants to remove a bunch of parts that currently exist or not. It wasn't specified that I know of
A quick search in the Roblox Wiki ends up with ClearAllChildren() to not accept any arguments - just do Remove() at all children.