Parallel
Functions for interacting with Roblox's parallel Luau Actors. These allow executing code across multiple Lua states and communicating between them.
checkparallel
Returns whether the current thread is executing inside a parallel context (Actor).
Aliases: isparallel
checkparallel() -> booleanExample
if checkparallel() then
print("Running in parallel!")
else
print("Running on main thread")
endget_actors
Returns a list of all "active" Actor instances that have been initialized with a Lua state.
Aliases: getactors
get_actors() -> {Actor}Example
local actors = get_actors()
print("Active actors:", #actors)
for _, actor in pairs(actors) do
print(actor:GetFullName())
endrun_on_actor
Schedules a script to execute on the specified Actor's Lua state.
Aliases: runonactor
run_on_actor(actor: Actor, script: string, comm_id: string?) -> void| Parameter | Type | Description |
|---|---|---|
actor | Actor | The Actor to run the script on |
script | string | The Lua source code to execute |
comm_id | string? | Optional communication channel ID for cross-actor messaging |
Example
local actors = get_actors()
if #actors > 0 then
run_on_actor(actors[1], [[
print("Hello from actor!")
]])
endon_actor_added
Registers a callback that fires whenever a new Actor's Lua state is created.
Aliases: onactoradded
on_actor_added(callback: function) -> void| Parameter | Type | Description |
|---|---|---|
callback | function | Called with the new Actor when its Lua state initializes |
Example
on_actor_added(function(actor)
print("New actor created:", actor:GetFullName())
end)Communication Channels
Communication channels allow you to send data between the main thread and Actor Lua states.
create_comm_channel
Creates a new communication channel and returns both its ID and the channel object.
Aliases: createcommchannel
create_comm_channel() -> (string, CommChannel)Returns:
string— The unique channel IDCommChannel— The channel object
get_comm_channel
Returns a communication channel by its ID. Works both inside Actors and on the main thread.
Aliases: getcommchannel
get_comm_channel(comm_id: string) -> CommChannel| Parameter | Type | Description |
|---|---|---|
comm_id | string | The communication channel ID |
Example
-- On main thread
local comm_id, channel = create_comm_channel()
-- Schedule code on an actor with the channel ID
local actors = get_actors()
if #actors > 0 then
run_on_actor(actors[1], [[
local channel = get_comm_channel(...) -- ... varargs is comm_id
-- Use channel to communicate back
]], comm_id)
end