Skip to main content
These are the names on rb itself rather than in a namespace, and require. A script reaches for them to read its own identity, to wait without blocking other scripts, and to split its code across files. Needs: a coroutine for rb.sleep, so call it inside rb.run, rb.after or rb.async (see Where code runs). This script prints its name and platform, counts three steps a second apart, and prints a line after five seconds:

rb.info

rb.info: RebindInfo, a read-only table available from the first line of the script.

rb.run

rb.run(fn: () -> ()) -> TaskHandle Runs fn as a coroutine and returns at once. The coroutine starts on the next engine tick. Inside it, rb.sleep and every other coroutine-only call work. An uncaught error inside the coroutine stops the whole script with that error and its traceback in the script’s Logs (see Where code runs). The returned TaskHandle stops the coroutine.

rb.sleep

rb.sleep(ms: number) -> () Pauses the current coroutine for ms milliseconds; fractions are allowed. Called outside a coroutine it raises Sleep() can only be called inside a Run() coroutine.

rb.after

rb.after(ms: number, fn: () -> ()) -> TaskHandle Runs fn once after ms milliseconds. It is rb.run around rb.sleep(ms) then fn(), so the same error rule applies.

rb.async

rb.async(fn: (...any) -> ...any) -> (...any) -> ...any Returns a function that runs fn in a coroutine. Called from outside a coroutine, the wrapper passes its arguments to fn inside a new rb.run and returns false. Called from inside a coroutine, it calls fn directly and returns fn’s results. Use it for rb.bind callbacks that need rb.sleep. Do not pass it straight to rb.on("down", ...): its false would block every key. This script holds W for half a second on F10:

require

require(module: string) -> any Loads a module file and returns its value. A module is a file that returns a value, usually a table. Each resolved file is evaluated once; later calls return the cached value. Resolution, relative to the script’s own directory, or to the package root for a script inside a package:
  • A leading ./ is stripped and dots are path separators, so require("lib.math") looks for lib/math.
  • Without an extension the candidates are <name>.luau, <name>.lua, <name>/init.luau, then <name>/init.lua. An explicit .luau or .lua suffix names that file only.
  • A name that directory cannot resolve is tried again in the packages folder of Rebind’s app directory, and a name starting with macros/ is tried in the macros folder of your scripts, where the recorder saves takes (macros. works the same way).
  • require("@rebind/pro") returns rb, for rb.ai and rb.phone (see Rebind Pro).
Errors: a name containing .., or a file that resolves outside the directory, raises require: path traversal not allowed: <name>; a name nothing matches raises module '<name>' not found (searched in <dir>). A required module needs no modeline of its own. See Splitting across files.

Where code runs

A script runs on the engine thread, which it shares with every other script and with input dispatch. Only rb.run, rb.after, and an rb.async wrapper called outside a coroutine start a coroutine. Everything else is a plain call, so a coroutine-only call such as rb.sleep, rb.hid.press, rb.net.get or rb.screen.capture raises there. To wait, start a coroutine with rb.run from inside the callback. Wrap work that may fail in pcall and report it with rb.log.error, so the message reaches the script’s Logs.