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

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

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?

1 comment

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.

2 answers

✓ Accepted answer
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

2 comments

0

Thanks, Ill check if this works now

0

vouch pls

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.

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