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.
Luau
run_on_thread(target: thread, source: string, ...args: CrossStateValue) -> ()Parameters
| Parameter | Type | Description |
|---|---|---|
target | thread | A thread returned by getactorthreads. |
source | string | Luau source string to run in its Actor state. |
...args | CrossStateValue | Cross-state values passed as varargs. |
Argument 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
Luau
local thread = getactorthreads()[1]
if thread then
run_on_thread(thread, 'local message = ...; print(message)', "Hello state")
end