Skip to content

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

lua
checkparallel() -> boolean

Example

lua
if checkparallel() then
    print("Running in parallel!")
else
    print("Running on main thread")
end

get_actors

Returns a list of all "active" Actor instances that have been initialized with a Lua state.

Aliases: getactors

lua
get_actors() -> {Actor}

Example

lua
local actors = get_actors()
print("Active actors:", #actors)

for _, actor in pairs(actors) do
    print(actor:GetFullName())
end

run_on_actor

Schedules a script to execute on the specified Actor's Lua state.

Aliases: runonactor

lua
run_on_actor(actor: Actor, script: string, comm_id: string?) -> void
ParameterTypeDescription
actorActorThe Actor to run the script on
scriptstringThe Lua source code to execute
comm_idstring?Optional communication channel ID for cross-actor messaging

Example

lua
local actors = get_actors()
if #actors > 0 then
    run_on_actor(actors[1], [[
        print("Hello from actor!")
    ]])
end

on_actor_added

Registers a callback that fires whenever a new Actor's Lua state is created.

Aliases: onactoradded

lua
on_actor_added(callback: function) -> void
ParameterTypeDescription
callbackfunctionCalled with the new Actor when its Lua state initializes

Example

lua
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

lua
create_comm_channel() -> (string, CommChannel)

Returns:

  • string — The unique channel ID
  • CommChannel — The channel object

get_comm_channel

Returns a communication channel by its ID. Works both inside Actors and on the main thread.

Aliases: getcommchannel

lua
get_comm_channel(comm_id: string) -> CommChannel
ParameterTypeDescription
comm_idstringThe communication channel ID

Example

lua
-- 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