getscriptfromthread Synchronous

Find the script Instance associated with a coroutine. Use it when you have a thread reference and need its script origin.

Syntax
Luau
getscriptfromthread(target: thread) -> ScriptInstance?

Parameters

Function parameters
ParameterTypeDescription
targetthreadCoroutine to inspect.

Returns

ScriptInstance?

A script Instance when the thread has one, or nil otherwise.

Usage notes

An executor-created coroutine may not belong to any Script Instance.

Example

Example
Luau
local owner = getscriptfromthread(coroutine.running())
print(owner and owner.Name or "No script for this thread")
Kawaii documentation