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

# rb.script

> Stop or reload the running script from its own code.

`rb.script` lets a script end itself or start over from its file. A script
reaches for it when its work is done, when it finds a state it cannot handle,
or when it wants to pick up an edited file.

This script does its setup once, then stops itself:

```luau theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
-- rebind: min_sdk=3.9.0 name=example version=1.0.0
rb.on("start", function()
  print("one-time setup done")
  rb.script.exit("setup finished")
  print("this line still runs; the script stops after this call returns")
end)

rb.on("stop", function()
  print("stop handlers run on exit too")
end)
```

| Signature | Effect |
| - | - |
| `rb.script.exit(reason: string?) -> ()` | stops the script after the current call returns; logs `Script exited: <reason>` |
| `rb.script.reload() -> ()` | reloads the script from its file; ignored when it was not loaded from a file |

When the script stops, its `rb.on("stop")` handlers run and every key and
button it still holds is released.

`exit(reason)` and `die(reason)` are global aliases of `rb.script.exit`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.