Roblox UtilitiesDevlHub Roblox Documentation

Class

Actor

Inherits
Model › PVInstance › Instance › Object
Memory category
BaseParts

An Actor is a container for code that can be safely split into its own thread.

An Actor is a container for code that can be safely split into its own thread using task.desynchronize(). It should also contain the instances used by its scripts.

To learn more about using multiple Actors to optimize script performance, see Parallel Luau.

Notes#

  • Each Actor runs in its own Luau VM. ModuleScripts required by an Actor are not shared or cached across Actors or with the main thread. Each VM executes its own copy of the module, so module-level state is isolated per Actor. Design accordingly if your modules hold state you intend to share.
  • script:GetActor() returns nil when called from a ModuleScript unless the ModuleScript is a descendant of the Actor. ModuleScripts stored elsewhere (for example, ReplicatedStorage) and required by an Actor are not considered descendants of the Actor.

Methods 3#

BindToMessageBinds a Luau callback to a message with the specified topic.Safe
BindToMessageParallelBinds a Luau callback to a message with the specified topic.Safe
SendMessageSends a message to an Actor.Safe

BindToMessage(topic: string, function: Function): RBXScriptConnection#

Safe

This method is used to bind a Luau callback to a message with the specified topic. When a message is sent (using SendMessage()) to the topic specified the provided callback will be called in a serial execution context.

Multiple Luau callbacks may be bound to a single actor and even to a single message topic.

Note: Only the scripts which are descendants of an Actor may bind to its messages.

NameTypeDefaultDescription
topicstringThe topic used to identify the type of message.
functionFunctionThe Luau callback to invoke when a message with the specified topic is received. The callback receives the message contents as its arguments.
Returns
  • RBXScriptConnection — This connection object may be used to disconnect the Luau callback from receiving messages.

BindToMessageParallel(topic: string, function: Function): RBXScriptConnection#

Safe

This method is used to bind a Luau callback to a message with the specified topic. When a message is sent (using SendMessage()) to the topic specified the provided callback will be called in a parallel execution context.

Multiple Luau callbacks may be bound to a single actor and even to a single message topic.

Note: Only the scripts which are descendants of an Actor may bind to its messages.

NameTypeDefaultDescription
topicstringThe topic used to identify the type of message.
functionFunctionThe Luau callback to invoke when a message with the specified topic is received. The callback receives the message contents as its arguments.
Returns
  • RBXScriptConnection — This connection object may be used to disconnect the Luau callback from receiving messages.

SendMessage(topic: string, message: Tuple): ()#

Safe

Sends a message to an Actor. Messages are sent asynchronously, so the sender will not block or yield when calling the SendMessage() method.

Since a single Actor may receive different kinds of messages, a topic parameter is used to distinguish between various kinds of messages.

See BindToMessage() for details on receiving a message sent using SendMessage().

Note that message arguments are passed by copy across Luau VM boundaries, not by reference. Sending large tables incurs a full copy on each call. Functions are bound to a specific VM and cannot be passed in messages.

NameTypeDefaultDescription
topicstringThe topic used to identify the message being sent.
messageTupleThe contents of the message to send to the Actor.
Returns
  • ()

Inherited members#

Inherited from Model 26
Inherited from PVInstance 4
Properties (2)

Origin, Pivot Offset

Methods (2)

GetPivot, PivotTo

Inherited from Instance 58
Inherited from Object 6
Properties (2)

ClassName, className

Events (1)

Changed