> ## 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.

# debug.getupvalue

Returns the upvalue at a given index in a closure or a running stack frame.

```luau theme={null}
debug.getupvalue(func: function | number, index: number): any
```

New to upvalues? [Learn more here](/docs/notes/#upvalues).

<Note>
  Give it a number instead of a function and the number is treated as a stack level - `0` is the call running right now, `1` its caller, and so on - and the upvalue comes from whatever closure is running there.
</Note>

Most commonly used while reversing a game script: grab a closure with `getgc` and
read its upvalues to see the state it holds before deciding whether to read, change, or
hook it.

## Parameters

| Parameter | Type                                                                 | Description                               |
| --------- | -------------------------------------------------------------------- | ----------------------------------------- |
| `func`    | <span style={{ whiteSpace: "nowrap" }}>`function` or `number`</span> | The closure to read from.                 |
| `index`   | `number`                                                             | Which upvalue to read, counting from `1`. |

## Returns

`any` - whatever the closure stored at that slot. The type is not fixed: a table, an
Instance, a function, and so on.

## Aliases

* `getupvalue`

## Example

A closure that captures a table, read straight back out by index:

<CodeGroup>
  ```luau Example 1 theme={null}
  local getupvalue = debug.getupvalue(function(...) end, 1)
  ```

  ```luau Example 2 theme={null}
  local store = {coins = 100}

  local function spend()
      store.coins -= 10
  end

  local up = debug.getupvalue(spend, 1) -- a table upvalue, never inlined out
  print(up == store, up.coins)
  ```
</CodeGroup>

<Tip>
  Give it a number instead of a function and the number is treated as a stack level - `0` is the call running right now, `1` its caller, and so on - and the upvalue comes from whatever closure is running there.
</Tip>
