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.

Syntax
Luau
run_on_actor(actor: Actor, source: string, ...args: CrossStateValue) -> ()

Parameters

Function parameters
ParameterTypeDescription
actorActorAn active Actor Instance.
sourcestringLuau source string to run in the Actor state.
...argsCrossStateValueCross-state values passed to the source 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 inactive Actor or missing owner raises an error.

Example

Example
Luau
local actor = getactors()[1]
if actor then
    run_on_actor(actor, 'local message = ...; print(message)', "Hello Actor")
end
Kawaii documentation