I am not a coder, which is why I need help with this.
I need a script that can be run in Studio and deletes specific objects. For example, I have places where there are mass amounts of objects that I don’t want like snap, weld, ClickDetector, etc… I would like to have a script that finds and deletes each one. Doing it manually would be ridiculously time consuming. Help would be much appreciated
for _, Object in pairs(workspace:GetDescendants()) do -- GetDescendants returns a table with all the objects descendants
if Object:IsA('ClickDetector') then -- Change this to whatever you want to delete
Object:Destroy()
end
end
edit: Keep in mind that IsA accepts superclasses as well, so doing
if Object:IsA('BasePart') then
will destroy Parts, MeshParts, PartOperations, VehicleSeats, TrussParts, CornerWedgeParts, FormFactorParts, WedgeParts, SkateboardPlatforms (yes thats a thing), FlagStands, Seats, SpawnLocations and Platforms
In the future, please remember that the Scripting Support Categories are not a venue to ask for code. As well, if a response helped you to solve your problem, do mark it as the solution.
In either case, since someone already went ahead and spoon fed code, I might as well build upon it since you asked to have several classes removed and the aforementioned code only removes one type:
-- My solution only works with exact object class names, you can't use abstract
-- classes (i.e. BasePart)
local classesToRemove = {
["Snap"] = true,
["ClickDetector"] = true,
}
for n, descendant in pairs(workspace:GetDescendants()) do
if classesToRemove[descendant.ClassName] then
classesToRemove:Destroy()
end
end
Adding an or statement to the code above is also acceptable in covering for more class types. See the Developer Hub for further information, such as on classes.