Skip to main content
Game-side threads spawned by a running LocalScript map back to that LocalScript Instance. The common source of valid threads is the table returned by getreg(){:luau}. Pass each thread from the registry to getscriptfromthread{:luau} and you get the owning script back. Multiple threads can map to the same script - one LocalScript can spawn many coroutines, and each one points to that same LocalScript. Most commonly used inside a hook to figure out which game script triggered the call, by passing coroutine.running(){:luau} from the hook body. Game-side threads spawned by a running LocalScript map back to that LocalScript Instance. The common source of valid threads is the table returned by getreg(). Pass each thread from the registry to getscriptfromthread and you get the owning script back. Multiple threads can map to the same script - one LocalScript can spawn many coroutines, and each one points to that same LocalScript. Most commonly used inside a hook to figure out which game script triggered the call, by passing coroutine.running() from the hook body.

Parameters

Returns

[LuaSourceContainer](https://create.roblox.com/docs/reference/engine/classes/LuaSourceContainer)? - the script that owns the given thread, or nil if the thread has no associated script. Instance?{:luau} - the script that owns t{:luau}, or nil{:luau} if no script owns it. Executor-created threads always return nil{:luau}.

Example

Print the owning script for every thread getreg(){:luau} returns. Threads with no game-side owner are skipped.
Game-side threads spawned by a running LocalScript map back to that LocalScript Instance. The common source of valid threads is the table returned by getreg(). Pass each thread from the registry to getscriptfromthread and you get the owning script back. Multiple threads can map to the same script - one LocalScript can spawn many coroutines, and each one points to that same LocalScript. Most commonly used inside a hook to figure out which game script triggered the call, by passing coroutine.running() from the hook body.

Parameters

Returns

Instance? - the script that owns t, or nil if no script owns it. Executor-created threads always return nil.

Example

gettenv(t).script returns the same Instance as getscriptfromthread(t) for any matching thread. Useful when you already have the thread’s env table on hand and don’t want a second call.

Example

Print the owning script for every thread getreg() returns. Threads with no game-side owner are skipped.
gettenv(t).script returns the same Instance as getscriptfromthread(t) for any matching thread. Useful when you already have the thread’s env table on hand and don’t want a second call.