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

?Is there a method to delete all children in workspace with the same name

Asked by 5 years ago

Basically, is there a method to delete all children in workspace with the same name. I am trying to make a tycoon regen script and i want to delete all BcopperIngot, BIroningot and bCopperOre that is currently in workspace. If there is not a method how would i be able to do it?

0
Return a table of the children in workspace using :GetChildren() then combine it with a for in pairs loop and check for any child named 'XYZ' then :Destroy() it. KardashevScale 110 — 5y

2 answers

Log in to vote
1
Answered by 5 years ago
local m = game.Workspace:GetChildren()

for i, v in pairs (m) do
if v.Name == "name" then
v:Destroy()
end
end)

yes i tested this and it worked, and you said remove so ill :Destroy() it

0
Thanks, Ill check if this works now FallenReju 3 — 5y
0
vouch pls MineBlow111 39 — 5y
Ad
Log in to vote
1
Answered by
valchip 789 Moderation Voter
5 years ago
Edited 5 years ago

You can do what @KardashevScale said in the comments, I am going to give some examples of you could do. First one is what Kardashev said:

for i, v in pairs (workspace:GetChildren()) do
    if v.Name == "IDK" then
        v:Destroy()
    end
end

Another way is to add the items with the same name in a folder and do workspace.Folder:ClearAllChildren().

Those are the 2 most efficient ways, pick the one you think is the best.

Answer this question