run_on_actor
Runs a script on an actor's state.
Syntax
run_on_actor(actor: Actor, script: string, ...: any) -> ()Parameters
| Parameter | Type | Description |
|---|---|---|
actor | Actor | The actor to run the script on |
script | string | The Luau code to execute |
... | any | Arguments 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 (
...)
Related Functions
getactors- Get active Actorscreate_comm_channel- Create communication channel