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

How can I make a script that deletes anything named "Car"?

Asked by 9 years ago

I already have a working script:

function Clean()
   while true do
      wait(5)
      script.Parent.Car:Destroy()
   end
end

Clean()

The script will delete anything inside Workspace called "Car" that is there, but when I spawn a new car in, it won't delete it.

2 answers

Log in to vote
2
Answered by 9 years ago

To get every car that could be deleted at once, you'll have to use GetChildren:

while true do
        wait(5)
        for _,v in ipairs(script.Parent:GetChildren()) do
        if v.Name == "Car" then
            v:Destroy()
        end
    end
end
Ad
Log in to vote
1
Answered by 9 years ago

To delete everything in workspace, you would want to do a for loop. this will let it go through the workspace looking for objects named car. I This would be done like so:

function Clean()

    for i,v in pairs(game.Workspace:GetChildren()) do
        if v.Name == "Car" then
            v:Destroy()
                wait()
        end
    end

Clean()

This will clean the workspace of anything named "Car" whenever this function is called

Answer this question