getscriptthread Synchronous

Search for a thread associated with a script Instance. Use it when you already know the script and need one matching active coroutine.

Syntax
Luau
getscriptthread(script: ScriptInstance) -> thread?

Parameters

Function parameters
ParameterTypeDescription
scriptScriptInstanceA LocalScript, ModuleScript, or Script whose RunContext is Client.

Returns

thread?

The first matching thread, or nil if no matching thread is found.

Usage notes

The wrapper scans available threads. A Script whose RunContext is not Client and any other class raise an error. Multiple threads can belong to one script, so this is not an exhaustive list.

Example

Example
Luau
local candidate = getscripts()[1]
if candidate then
    local ok, thread = pcall(getscriptthread, candidate)
    if ok then print("Found thread:", thread ~= nil) end
end