Filtering children of an Instance using function?

Hello, I was wondering if there is something similar to the code I have written below.

local part = workspace.Part -- A part in the workspace with many types of instances within it
local filtered = part:GetChildren(function(child)
    return (child.ClassName == "Script" and child or nil)
end)
print(filtered) --[[ // { Script, Script, Script } ]]--

I pass in a function to get children to filter out only specific instances that I want. Does something like this already exist, maybe not exactly like this.

How I do it currently:

local part = workspace.Part
local filtered = {}
for _, child in pairs(part:GetChildren()) do
    if (child.ClassName == "Script") then
        table.insert(filtered, child)
    end
end
print(filtered)

There is no function roblox has for that.

3 Likes