I feel this can be pretty useful for clearing specific items when there are other existing items at play; However, I feel like each example - while similar - has its own use case for a specific purpose, where :ClearAllChildren()
is for when you need to remove everything, while a for
loop allows you to customize what specific condition should occur when it finds a specific object.
One example (which is the main reason people want it in the first place) would be when you have a hirearchy of disposable items of the same class, but you have objects that are essential for all the said disposable items. What it could do is only remove the disposable items when you specify their class, and only the essentials remain for later use of more disposable items.
Though, the alternative I can think of is CollectionService
to identify and dispose of the disposable items:
for _,v in CollectionService:GetTagged("DisposableFrames") do
v:Destroy()
end
In my opinion, its cool, has its cases, and would be very convinient for said cases.
Maybe an argument can be incorporated into the already existing function for those cases, like:
- No Argument = Clear all Instances
- Argument with a unknown class = Errors (Class does not exist or something idk)
- Argument with a class = clear all children under class
I feel like the same could be said about stuff like :FindFirstChildOfClass()
or :FindFirstChildWhichIsA()
.
While there are a few cases you might use them here are there, is much better than doing:
for _,v in this:GetChildren() do
if not v:IsA(that) then continue end
return v
end
-- when you can just say this:
this:FindFirstChildOfClass(That)
Even :ClearAllChildren()
,
where all thats needed for it is:
for _,v in this:GetChildren() do
v:Destroy()
end
Another one being :WaitForChild()
, where before 2013,
you had to create the whole function in order to get something you wanted to load in:
--// THEN
function waitForChild(parent, childName)
local child = parent:findFirstChild(childName)
if child then return child end
while true do
child = parent.ChildAdded:wait()
if child.Name==childName then return child end
end
end
local object = waitForChild(This, "That")
--// NOW
local object = This:WaitForChild("That") -- takes up a single line
-- very convinient and people take that for granted now