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 client-running Script.

Returns

thread?

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

Usage notes

The wrapper scans available threads; a Script using server RunContext is rejected. 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
Kawaii documentation