Class
Actor
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
Actorruns in its own Luau VM.ModuleScriptsrequired by anActorare not shared or cached acrossActorsor with the main thread. Each VM executes its own copy of the module, so module-level state is isolated perActor. Design accordingly if your modules hold state you intend to share. script:GetActor()returnsnilwhen called from aModuleScriptunless theModuleScriptis a descendant of theActor.ModuleScriptsstored elsewhere (for example,ReplicatedStorage) and required by anActorare not considered descendants of theActor.
Methods 3#
| BindToMessage | Binds a Luau callback to a message with the specified topic.Safe |
| BindToMessageParallel | Binds a Luau callback to a message with the specified topic.Safe |
| SendMessage | Sends 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.
| Name | Type | Default | Description |
|---|---|---|---|
topic | string | The topic used to identify the type of message. | |
function | Function | The 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.
| Name | Type | Default | Description |
|---|---|---|---|
topic | string | The topic used to identify the type of message. | |
function | Function | The 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.
| Name | Type | Default | Description |
|---|---|---|---|
topic | string | The topic used to identify the message being sent. | |
message | Tuple | The contents of the message to send to the Actor. |
Returns
()
Inherited members#
Inherited from Model 26
Properties (5)
LevelOfDetail, ModelStreamingMode, PrimaryPart, Scale, WorldPivot
Methods (21)
AddPersistentPlayer, BreakJoints, breakJoints, GetBoundingBox, GetExtentsSize, GetModelCFrame, GetModelSize, GetPersistentPlayers, GetPrimaryPartCFrame, GetScale, MakeJoints, makeJoints, move, MoveTo, moveTo, RemovePersistentPlayer, ResetOrientationToIdentity, ScaleTo, SetIdentityOrientation, SetPrimaryPartCFrame, TranslateBy
Inherited from Instance 58
Properties (10)
Archivable, archivable, Capabilities, IsInSandbox, Name, Parent, PredictionMode, RobloxLocked, Sandboxed, UniqueId
Methods (39)
AddTag, children, ClearAllChildren, Clone, clone, Destroy, destroy, FindFirstAncestor, FindFirstAncestorOfClass, FindFirstAncestorWhichIsA, FindFirstChild, findFirstChild, FindFirstChildOfClass, FindFirstChildWhichIsA, FindFirstDescendant, GetActor, GetAttribute, GetAttributeChangedSignal, GetAttributes, GetChildren, getChildren, GetDebugId, GetDescendants, GetFullName, GetStyled, GetStyledPropertyChangedSignal, GetTags, HasTag, IsAncestorOf, IsDescendantOf, isDescendantOf, IsPropertyModified, QueryDescendants, Remove, remove, RemoveTag, ResetPropertyToDefault, SetAttribute, WaitForChild