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.
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