run_on_actor

Runs a script on an actor's state.

Syntax

run_on_actor(actor: Actor, script: string, ...: any) -> ()

Parameters

ParameterTypeDescription
actorActorThe actor to run the script on
scriptstringThe Luau code to execute
...anyArguments passed to the script

Returns

This function does not return a value.

Description

run_on_actor executes the provided Luau source on the specified Actor.

Example

local actor = assert(getactors()[1], "No active actor state")

run_on_actor(actor, [[
    print("Hello from actor!")
    print("Arguments:", ...)
]], "arg1", "arg2")

With Communication Channel

local id, channel = create_comm_channel()
channel.Event:Connect(function(message)
    print("Received:", message)
end)

local actor = assert(getactors()[1], "No active actor state")
run_on_actor(actor, [[
    local channelId = ...
    local channel = get_comm_channel(channelId)
    channel:Fire("Hello from actor!")
]], id)

Notes

  • The Actor must be active
  • Use communication channels to send data back
  • Arguments are passed via varargs (...)