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

# setthreadidentity

Sets the current thread's identity to `identity` and returns the level that was active before the call.

```luau theme={null}
setthreadidentity(identity: number): number
```

Every thread on Roblox carries an identity number that decides what the running script is allowed to touch.<br />Read the `getthreadidentity` page entry to learn more.

## Parameters

| Parameter  | Type     | Description                                    |
| ---------- | -------- | ---------------------------------------------- |
| `identity` | `number` | The new identity level for the current thread. |

## Returns

`number` - the previous identity (the level that was active before this call). Useful for save/restore: capture the return, do your work at the new identity, then pass it back into a second call to restore.

## Aliases

* `setidentity`
* `set_thread_identity`
* `setthreadcontext`

## Example

If you try to `require()` a ModuleScript, while having your identity level set to `2`, <br />you will get an error: `Lacking capability RobloxScript`.

<CodeGroup>
  ```luau Example 1 theme={null}
  <<<<<<< HEAD
  local setthreadidentity = setthreadidentity(8)
  =======
  -- setthreadidentity(identity: number): number
  >>>>>>> 50e30f53759b0538759af25c9b271514aa2c9290
  ```

  ```luau Example 2 theme={null}
  local rep = cloneref(game:GetService('ReplicatedStorage'))
  --local module = getrenv().require(rep.Modules.SomeModule)
  -- Example above will error!

  local prev = setidentity(2)
  local module = getrenv().require(rep.Modules.SomeModule)
  -- Now it will execute without errors.

  setidentity(prev)
  -- ...
  ```
</CodeGroup>

<Tip>
  Always check parameters and return values when working with this library function.
</Tip>
