Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.