Threads

getscriptfromthread

Returns the Script Instance associated with a Luau thread, or nil when no valid script reference is available.

Syntax

getscriptfromthread(thread: thread): Instance | nil

Arguments

NameTypeDescription
threadthreadLuau thread whose associated Script Instance is returned.

Returns

NameTypeDescription
scriptInstance | nilAssociated Script Instance when available; otherwise nil.

Description

Returns the Script Instance associated with a Luau thread, or nil when no valid script reference is available.

Call it with 1 parameter(s): thread. The argument table explains which values are required and which ones only refine the behavior.

It returns script (Instance | nil). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Read the Script Instance stored on a Luau thread, if one is attached.

local thread = coroutine.create(function()
end)

local scriptInstance = getscriptfromthread(thread)
print(scriptInstance)