Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I need help with a unwanted entity remover. [?]

Asked by 8 years ago

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

1 answer

Log in to vote
0
Answered by 8 years ago

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.

0
To achieve what he wants you would have to check newly added children or put this in a loop. :) NotsoPenguin 705 — 8y
0
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 alphawolvess 1784 — 8y
0
A quick search in the Roblox Wiki ends up with ClearAllChildren() to not accept any arguments - just do Remove() at all children. Marios2 360 — 8y
Ad

Answer this question