> ## Documentation Index
> Fetch the complete documentation index at: https://docsuncv2.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# filtergc

Returns functions or tables from the GC pool that match what you ask for.

```luau theme={null}
filtergc(filterType: "function" | "table", filterOptions: table, returnOne: boolean?): {any} | any?
```

`filterOptions` is always a table. The more criteria you pass in it, the narrower the result set.

This function only sees values still referenced by a live thread. Once a reference drops, the value is gone before the call ever runs.

Most commonly used to find a Luau closure to hook, or to find an object you want to investigate.

## Parameters

| Parameter       | Type                    | Description                                          |
| --------------- | ----------------------- | ---------------------------------------------------- |
| `filterType`    | `"function" \| "table"` | Picks which GC value type to filter.                 |
| `filterOptions` | `table`                 | Criteria the value must match.                       |
| `returnOne`     | `boolean?`              | If `true`, return the first match instead of a list. |

## Returns

`{any} | any?` - shape depends on `returnOne`:

| `returnOne` value          | Returned shape                                            |
| -------------------------- | --------------------------------------------------------- |
| omitted, `nil`, or `false` | `{any}` - table of every match. Empty if nothing matched. |
| `true`                     | `any` - the first match, or `nil` if nothing matched.     |

## Example

In a Roblox game, locate a uniquely-named Luau function with `filtergc("function", {Name = "..."}, true)`, hook it with `hookfunction`, and verify the hook fires when the function is called.

<CodeGroup>
  ```luau Example 1 theme={null}
  <<<<<<< HEAD
  local filtergc = filtergc("Line", "test", false)
  =======
  -- filtergc(filterType: "function" | "table", filterOptions: table, returnOne: boolean?): {any} | any?
  >>>>>>> 50e30f53759b0538759af25c9b271514aa2c9290
  ```

  ```luau Example 2 theme={null}
  local target = filtergc("function", {Name = "RequestMoney"}, true)
  if not target then warn('aaaa') return end

  local original = hookfunction(target, function(...)
      print(`that function was called`)
      return original(...)
  end)

  print(`hook installed on {target}`)
  ```
</CodeGroup>

<Tip>
  Much faster than manually traversing `getgc()` outputs.
</Tip>
