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

# Scripts

> Script, bytecode, and environment queries.

Script, bytecode, and environment queries.

| Function navigation                            | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [`decompile`](./decompile)                     | Decompiles a Roblox script and returns the generated source text when bytecode is available. The argument must be a supported script Instance. If usable bytecode is not available, the function returns nil.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| [`dumpstring`](./dumpstring)                   | Returns the decompressed bytecode string for a Roblox script object. dumpstring is registered to the same behavior as getscriptbytecode, so its behavior is identical. The argument must be object. The bytecode behavior accepts ClassName values ModuleScript, LocalScript, CoreScript, and Script. For Script, RunContext must be Client. If ClassName is missing, the function raises "Invalid Instance". If ClassName is not one of the supported script classes, it raises "Script expected". If the value is a Script with another RunContext, it raises "Expected a Script with RunContext set to Client". If the embedded bytecode reference is invalid or the stored bytecode length is 8 bytes or less, the function returns nil. Otherwise it decompresses the stored bytecode with DecompressBytecode and returns the resulting bytes as a Luau string. Hash mismatch, too-short compressed data, or ZSTD decompression errors are returned as their error text bytes by DecompressBytecode rather than being raised here. |
| [`getcallingscript`](./getcallingscript)       | Returns the Script Instance associated with the current Luau thread, or nil when no script is associated with it.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| [`getinstancesbyclass`](./getinstancesbyclass) | Returns instances from the Instance cache table whose ClassName field exactly matches the requested string. The first argument is required to be a string. An empty string raises "ClassName required". The function creates a new array table, iterates the cache stored under Instance cache, keeps only values whose Lua type is object, reads each object value's ClassName field, and compares it with strcmp against the requested className. Matches are inserted sequentially starting at index 1. The match is exact and case-sensitive. The function does not use IsA, does not include subclasses, does not walk descendants, does not filter by Parent, and does not sort the result. getinstancesofclass is an alias for the same function.                                                                                                                                                                                                                                                                                |
| [`getloadedmodules`](./getloadedmodules)       | Returns a new array table containing live entries from loaded module list. The optional excludeCore argument is read with optional boolean handling and defaults to true when omitted or nil. If excludeCore is true, entries whose instance is a descendant of core packages or CoreGui are skipped. Expired weak entries and locked stored references without a value are skipped. The function pushes each remaining entry with Instance cache at sequential array indexes starting at 1. The function does not check ClassName, does not sort the result, and does not walk the DataModel.                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| [`getmenv`](./getmenv)                         | Returns the environment table associated with a ModuleScript. The argument must be a ModuleScript object. Invalid objects raise "Invalid Instance", non-ModuleScript objects raise "ModuleScript expected", and ModuleScripts without an available thread raise "invalid thread". The function does not accept Script or LocalScript; use getsenv for those cases.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| [`getreferencedby`](./getreferencedby)         | Returns cached Instance values whose supported reference properties point to the provided Instance. The argument must be an Instance.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [`getrunningscripts`](./getrunningscripts)     | Returns a new array table of unique script Instances taken from live Lua threads. The function takes no arguments. It walks the live Luau thread list, reads each thread node, skips entries without a thread node, without a weak thread ref, without LiveLuaRef, without a Lua state, without object, or with an expired Script stored reference. For each remaining thread, it locks scriptThread->object->Script(), deduplicates by the script reference, pushes the Instance with Instance cache, and inserts it at sequential array indexes starting at 1. The function does not scan the DataModel, does not check ClassName, and does not sort the result.                                                                                                                                                                                                                                                                                                                                                                      |
| [`getscriptbytecode`](./getscriptbytecode)     | Returns the decompressed bytecode string for a Roblox script object. getscriptbytecode is registered to the same behavior as dumpstring, so its behavior is identical. The argument must be object. The bytecode behavior accepts ClassName values ModuleScript, LocalScript, CoreScript, and Script. For Script, RunContext must be Client. If ClassName is missing, the function raises "Invalid Instance". If ClassName is not one of the supported script classes, it raises "Script expected". If the value is a Script with another RunContext, it raises "Expected a Script with RunContext set to Client". If the embedded bytecode reference is invalid or the stored bytecode length is 8 bytes or less, the function returns nil. Otherwise it decompresses the stored bytecode with DecompressBytecode and returns the resulting bytes as a Luau string. Hash mismatch, too-short compressed data, or ZSTD decompression errors are returned as their error text bytes by DecompressBytecode rather than being raised here. |
| [`getscriptclosure`](./getscriptclosure)       | Loads the stored bytecode for a supported Roblox script Instance and returns it as a Lua closure. Returns nil when usable bytecode is not available.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| [`getscripthash`](./getscripthash)             | Returns an uppercase SHA384 hex digest for the stored bytecode string of a Roblox script object. The argument must be object. The bytecode behavior accepts ClassName values ModuleScript, LocalScript, CoreScript, and Script. For Script, RunContext must be Client. If ClassName is missing, the function raises "Invalid Instance". If ClassName is not one of the supported script classes, it raises "Script expected". If the value is a Script with another RunContext, it raises "Expected a Script with RunContext set to Client". If the embedded bytecode reference is invalid or the stored bytecode length is 8 bytes or less, the function returns nil. Otherwise it hashes the exact stored bytecode bytes with SHA384 and returns the uppercase hex string. The function does not call DecompressBytecode and does not hash decompressed bytecode.                                                                                                                                                                     |
| [`getscripts`](./getscripts)                   | Returns script object values currently present in the Instance cache. The function takes no arguments. It iterates the cache stored under the Instance cache and only considers entries whose value is object. It reads each value's ClassName field with optional string handling. LocalScript and ModuleScript entries are included. Script entries are included only when their RunContext offset equals CLIENT or PLUGIN. Other ClassName values, entries without a string ClassName, and CoreScript entries are skipped. The result is a sequential Luau table. The function does not traverse the DataModel and does not guarantee sorted order.                                                                                                                                                                                                                                                                                                                                                                                  |
| [`getscriptthread`](./getscriptthread)         | Returns the Lua thread associated with a script object when Real can find one. The argument must be object. The function reads the value's ClassName field and raises "not a valid Instance" if that field is not a string. Accepted ClassName values are Script, LocalScript, and ModuleScript; any other value raises "Script expected". It first checks Real's ScriptThreadCache by the script reference. On a cache hit, it returns the cached Luau thread as a thread. On a cache miss, Script values must have RunContext Client or the function raises "Expected a Script with RunContext set to Client". It then walks the live Luau thread list, follows each thread node's first weak thread reference to LiveLuaRef, skips missing thread data or expired Script stored references, and compares each script reference with the requested script. If it finds a match, it returns that Luau thread as a thread. If no match is found, it returns nil.                                                                        |
| [`getsenv`](./getsenv)                         | Returns the environment table associated with a LocalScript, Script, or ModuleScript. Unsupported script objects or scripts without an available thread raise the same errors as the underlying script lookup.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| [`loadstring`](./loadstring)                   | Compiles a Luau source string and returns the loaded function. If loading fails, it returns nil and an error message. The returned function is not executed automatically.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
