getscriptthread

Returns a thread associated with a client script or ModuleScript.

Syntax

getscriptthread(script: LocalScript | ModuleScript | Script) -> thread?

Parameters

ParameterTypeDescription
scriptLocalScript, ModuleScript, or client ScriptScript whose thread should be found

Returns

TypeDescription
thread?The associated thread, or nil when none is available

Example

local runningScript = getrunningscripts()[1]
local thread = runningScript and getscriptthread(runningScript)

if thread then
    print(coroutine.status(thread))
    print(getscriptfromthread(thread) == runningScript) -- true
else
    warn("No running script thread was available")
end