getscriptthread
Returns the main thread of a running script.
Syntax
getscriptthread(script: LuaSourceContainer) -> thread?
Also available as
get_script_thread
Parameters
| Parameter | Type | Description |
|---|---|---|
script | LuaSourceContainer | A LocalScript, Script or ModuleScript. |
Returns
| Type | Description |
|---|---|
thread? | The thread the script's main chunk ran on, or nil when it has not run. |
Description
This is the thread the engine started the script on. Pass it to gettenv for the script's globals, to getcallstack to see where it is waiting, when it belongs to the current VM. Do not resume or close engine-owned or foreign-state threads as though they were ordinary local coroutines.
Example
local main = game.Players.LocalPlayer.PlayerScripts:FindFirstChild("ClientMain")
local thread = main and getscriptthread(main)
print(thread and coroutine.status(thread))
These are Game executor contracts. Check build requirements and session lifetimes before using them.
