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

Is There a way of destroying everything in the workspace in the same name?

Asked by 6 years ago

Hello, is there a way i can delete everything that is called the same name in a script?

for example, i have everything as decal, i don't want to delete it manually, Is there a way?

local asdnew = Instance.new("TextButton",ScreenGui)
asdnew.BackgroundColor3 = Color3.new(0,0,0)
asdnew.BorderColor3 = Color3.new(0,0,0)
asdnew.Name = "nooties"
asdnew.Position = UDim2.new(1,-150,1,-90)
asdnew.Size = UDim2.new(0,150,0,45)
asdnew.Font = "SourceSansBold"
asdnew.FontSize = "Size14"
asdnew.Text = "Destroy"
asdnew.TextColor3 = Color3.new(255,255,255)
asdnew.MouseButton1Click:connect(function()
    game.Workspace.Sound:Destroy()
    game.Lighting:Destroy()
    game.Workspace.Terrain:Destroy()()
    game.Workspace.Camera:ClearAllChildren()()
    game.Workspace._CPData:ClearAllChildren()

2 answers

Log in to vote
0
Answered by
Leamir 3138 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

Hello, TheEdyGamerTroll23!

This script will destroy everithing with the names on table that are on workspace!

local DestroyList = {"ThingOne","ThingTwo"} -- Things name to destroy here(!!Just From Workspace!!)
local DestroyDescendants = {"ThingOne","ThingTwo"} -- Things name to destroy here(!!!From Workspace and its Descendants!!!)

function Destroy()
    for _,Object in pairs(game.Workspace:GetDescendants()) do
        for _,WorkspaceItem in pairs(DestroyList) do
            for _,Descendants in pairs(DestroyDescendants) do
                if Object.Name == WorkspaceItem then
                    Object:Destroy() -- Destroys Workspace items
                end
                if Object.Name == Descendants then
                    Object:Destroy() -- Destroys Childs of Items =D
                end
            end
        end
    end
end

Destroy() -- Calls the function to destroy the parts in workspace!

Read the comments!

This script will destroy when you PLAY the game, parts will still be in studio

Good Luck with your games!

0
I mean that when i press a button it do the action i want TheEdyGamerTroll23 15 — 6y
0
you can place this script on a function an then call it =D Leamir 3138 — 6y
0
so i can use the same script with a button, likfe Mouse1Click? TheEdyGamerTroll23 15 — 6y
0
yes Leamir 3138 — 6y
View all comments (7 more)
0
This script can be on any part, it will aways get the workspace Leamir 3138 — 6y
0
Ok, Thanks! :D TheEdyGamerTroll23 15 — 6y
0
I would be lots happy if you accept my answer =D Leamir 3138 — 6y
0
In Function Destroy() it tells me to change it to local :( TheEdyGamerTroll23 15 — 6y
0
have you changed something inside of the function? Leamir 3138 — 6y
1
another advice: try not to name your functions the same name as roblox api functions such as Destroy() Nonaz_jr 439 — 6y
0
Thanks for the advices, Nonaz! Leamir 3138 — 6y
Ad
Log in to vote
0
Answered by
Nonaz_jr 439 Moderation Voter
6 years ago
local itemName = "ENTER ITEMNAME" --enter name of item here
local item = game.Workspace:FindFirstChild(itemName,true)
while item do 
  item:Destroy() 
  item = game.Workspace:FindFirstChild(itemName,true)
end

it's slow but it works :D

or loop over everything

local function destroyAll(list)
  for index, child in pairs(list) do
    if child.Name == "ENTER NAME HERE" and child:IsA("Decal") then --enter item info here
       child:Destroy()
    else
       destroyAll(child:GetChildren())
    end
  end
end
destroyAll(game.Workspace:GetChildren())

allows you to check the item type and is much faster if you have lots of stuff.. ALL CODE UNTESTED bugfix for yourself

0
so i did test it and it works afterall yay no typos Nonaz_jr 439 — 6y

Answer this question