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

Replaces the constant at `index` in a Luau function's constant table with `value`.

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

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

The replacement takes effect the next time that function runs. Pass a Luau function to target its constant table, or a number for the running function at that stack level.

Indices come from the compiled constant table, not the source you read. The compiler folds math and string concatenation and strips dead code, so a decompiled listing may not line up one-to-one.

Most often used to change a value a game's code checks against: swap the number or text it compares to, and a check that should fail can pass instead.

## Parameters

| Parameter | Type                                                                 | Description                 |
| --------- | -------------------------------------------------------------------- | --------------------------- |
| `func`    | <span style={{ whiteSpace: "nowrap" }}>`function` or `number`</span> | The Luau function to patch. |
| `index`   | `number`                                                             | Which constant to replace.  |
| `value`   | `any`                                                                | The replacement value.      |

## Returns

<code title="the function does not return a value.">void</code> - the target's constant table is mutated in place.

## Aliases

* `setconstant`

## Example

In a Roblox game, a function returns a hardcoded number you want to override. Find the constant's index, then repatch it.

<CodeGroup>
  ```luau Example 1 theme={null}
  debug.setconstant(function(...) end, 1, "test")
  ```

  ```luau Example 2 theme={null}
  local function getMaxAmmo()
      return 30
  end

  print(getMaxAmmo()) --> 30

  -- index 1 is the number literal 30, the only constant in this body
  debug.setconstant(getMaxAmmo, 1, 999)

  print(getMaxAmmo()) --> 999
  ```
</CodeGroup>

<Tip>
  Modifying constants affects all subsequent calls to the targeted function.
</Tip>
