run_on_thread Asynchronous

  • runonthread

Run source in the state associated with a thread proxy from getactorthreads. This is useful when you already selected a state by its published thread proxy.

Syntax
Luau
run_on_thread(target: thread, source: string, ...args: CrossStateValue) -> ()

Parameters

Function parameters
ParameterTypeDescription
targetthreadA thread returned by getactorthreads.
sourcestringLuau source string to run in its Actor state.
...argsCrossStateValueCross-state values passed as varargs.

Argument fields

CrossStateValue fields
Luau
CrossStateValue = nil | boolean | number | string | Instance | {[CrossStateValue]: CrossStateValue}

Returns

()

No value.

Usage notes

The source starts in the target state and runs until it finishes or first yields. This call does not return the chunk’s results; later work can continue in the target state.

Only nil, booleans, numbers, strings, Instances, and tables of those values can cross states. Functions, threads, buffers, and other userdata cannot.

An arbitrary coroutine is rejected; the thread must come from getactorthreads and still refer to an active state.

Example

Example
Luau
local thread = getactorthreads()[1]
if thread then
    run_on_thread(thread, 'local message = ...; print(message)', "Hello state")
end
Kawaii documentation