run_on_actor Asynchronous
runonactor
Compile and start source in the active state belonging to an Actor. This is useful when a small piece of work must run where that Actor lives.
Luau
run_on_actor(actor: Actor, source: string, ...args: CrossStateValue) -> ()Parameters
| Parameter | Type | Description |
|---|---|---|
actor | Actor | An active Actor Instance. |
source | string | Luau source string to run in the Actor state. |
...args | CrossStateValue | Cross-state values passed to the source 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 inactive Actor or missing owner raises an error.
Example
Luau
local actor = getactors()[1]
if actor then
run_on_actor(actor, 'local message = ...; print(message)', "Hello Actor")
end