Ir para o conteúdo principal
Version: latest - a1.172.0 ⚖️

Base Entity

Entity is the base for all Classes, and all those entities share the same Methods and Events described in this page

👪Base Class🧑‍💻API Source
👪Base Class
This is a Base Class, an abstract definition that shares common methods and events with it's child classes. You cannot spawn it, and you cannot call anything on the Base Class name itself. Use any class that inherits it.

Classes that share methods and events from this Base Class: Billboard, Blueprint, Cable, Canvas, Character, CharacterSimple, Decal, Gizmo, Grenade, InstancedStaticMesh, Light, Melee, Particle, Player, Prop, SceneCapture, StaticMesh, Sound, TextRender, Text3D, Trigger, VehicleWheeled, VehicleWater, Weapon, WebUI, Widget, Widget3D.

🗿 Static Functions​

Class
GetInheritedClasses: table of tableGets a list of all directly inherited classes from this Class created with the Inheriting System
GetParentClass: table or nilGets the parent class if this Class was created with the Inheriting System
Inherit: tableInherits this class with the Inheriting System
IsChildOf: booleanGets if this Class is child of another class if this Class was created with the Inheriting System
Events
Subscribe: functionSubscribes to an Event for all entities of this Class
UnsubscribeUnsubscribes all callbacks from this Event in this Class within this Package, or only the callback passed
Network
SubscribeRemote: functionSubscribes to a custom event called from server
Queries
GetAll: table of Base EntityReturns a table containing all Entities of the class this is called on
GetByIndex: Base EntityReturns a specific Entity of this class at an index
GetCount: integerReturns how many Entities of this class exist
GetPairs: iteratorReturns an iterator with all Entities of this class to be used with pairs()

Classstatic functions​

GetInheritedClassesModerate​

Gets a list of all directly inherited classes from this Class created with the Inheriting System

local ret = <AnyEntityClass>.GetInheritedClasses(recursively?)
Parameters
NameTypeDescrição
recursively?booleanReturns all inherited children Default false
Returns
TypeDescrição
table of tableAll children Classes

GetParentClassOptimal​

Gets the parent class if this Class was created with the Inheriting System

local ret = <AnyEntityClass>.GetParentClass()
Returns
TypeDescrição
table or nilThe parent class

InheritSlow​

Inherits this class with the Inheriting System

local class = <AnyEntityClass>.Inherit(name, custom_values?)
Parameters
NameTypeDescrição
namestringThe name of the new Class
custom_values?tableAn optional table with custom values to be set in the inherited class table Default {}
Returns
TypeDescrição
tableThe new Class table

IsChildOfOptimal​

Gets if this Class is child of another class if this Class was created with the Inheriting System

local ret = <AnyEntityClass>.IsChildOf(class)
Parameters
NameTypeDescrição
classtableThe other class to check
Returns
TypeDescrição
booleanWhether this Class is child of another class if this Class was created with the Inheriting System

Eventsstatic functions​

SubscribeOptimal​

Subscribes to an Event for all entities of this Class

local ret = <AnyEntityClass>.Subscribe(event_name, callback)
Parameters
NameTypeDescrição
event_namestringName of the event to subscribe to
callbackfunctionFunction to call when the event is triggered
Returns
TypeDescrição
functionCallback that was passed (useful for unsubscribing later if your callback is an anonymous function)

UnsubscribeOptimal​

Unsubscribes all callbacks from this Event in this Class within this Package, or only the callback passed

<AnyEntityClass>.Unsubscribe(event_name, callback?)
Parameters
NameTypeDescrição
event_namestringName of the event to unsubscribe from
callback?functionOptional callback to unsubscribe Default nil

Networkstatic functions​

SubscribeRemoteOptimal​

Subscribes to a custom event called from server

local ret = <AnyEntityClass>.SubscribeRemote(event_name, callback)
Parameters
NameTypeDescrição
event_namestringName of the event to subscribe to
callbackfunctionFunction to call when the event is triggered
Returns
TypeDescrição
functionCallback that was passed (useful for unsubscribing later if your callback is an anonymous function)

Queriesstatic functions​

GetAllModerate​

Returns a table containing all Entities of the class this is called on

local ret = <AnyEntityClass>.GetAll()
Returns
TypeDescrição
table of Base EntityCopy of table containing all Entities

GetByIndexOptimal​

Returns a specific Entity of this class at an index

local ret = <AnyEntityClass>.GetByIndex(index)
Parameters
NameTypeDescrição
indexintegerThe index of the Entity
Returns
TypeDescrição
Base EntityEntity at index

GetCountOptimal​

Returns how many Entities of this class exist

local ret = <AnyEntityClass>.GetCount()
Returns
TypeDescrição
integerNumber of Entities of this class

GetPairsOptimal​

Returns an iterator with all Entities of this class to be used with pairs()

This is a more performant method than GetAll(), as it will return the iterator to access the Entities directly instead of creating and returning a copy of the Entities table.

Note: Destroying Entities from inside a GetPairs() loop will cause the iterable to change size during the process. If you want to loop-and-destroy, please use GetAll()

local ret = <AnyEntityClass>.GetPairs()
Returns
TypeDescrição
iteratorIterator with all Entities of this class

🦠 Functions​

Class
GetClass: tableGets the class of this entity
IsA: booleanRecursively checks if this entity is inherited from a Class
Data
GetAllValuesKeys: table of stringGets a list of all values keys
GetValue: anyGets a Value stored on this Entity at the given key
SetValueSets a Value in this Entity
Events
Subscribe: functionSubscribes to an Event on this specific entity
UnsubscribeUnsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed
Lifecycle
DestroyDestroys this Entity
FinishSpawnFinish the spawning process and send the entity to clients if it was spawned with a deferred spawn_mode
IsBeingDestroyed: booleanReturns true if this Entity is being destroyed
IsSpawned: booleanGets if this Entity finished spawning
IsValid: booleanReturns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity)
SetSpawnModeOverrides when this Entity finishes spawning, from the Constructor of an Inherited Class
Network
BroadcastRemoteEventCalls a custom remote event directly on this entity to all Players
BroadcastRemoteInRadiusEventCalls a custom remote event directly on this entity to all Players in a radius
CallRemoteEventCalls a custom remote event directly on this entity to a specific Player
CallRemoteEventCalls a custom remote event directly on this entity
CallRemotePlayersEventCalls a custom remote event directly on this entity to a list of Players
HasAuthority: booleanGets if the local context has authority over this Entity (true if spawned by the client, false if spawned by the server)
SubscribeRemote: functionSubscribes to a custom event called from server on this specific entity
Queries
GetID: integerGets the universal network ID of this Entity (same on both client and server)

Classfunctions​

GetClassOptimal​

Gets the class of this entity

local class = my_entity:GetClass()
Returns
TypeDescrição
tableClass of this entity

IsAModerate​

Recursively checks if this entity is inherited from a Class

local ret = my_entity:IsA(class)
Parameters
NameTypeDescrição
classtableThe Class
Returns
TypeDescrição
booleanWhether this entity is of that class or inherits from it

Datafunctions​

GetAllValuesKeysModerate​

Gets a list of all values keys

local ret = my_entity:GetAllValuesKeys()
Returns
TypeDescrição
table of stringa list with all values keys

See also GetValue, SetValue.

GetValueOptimal​

Gets a Value stored on this Entity at the given key

Please refer to Entity Values for more information

local value = my_entity:GetValue(key, fallback)
Parameters
NameTypeDescrição
keystringThe key
fallbackanyFallback value if key doesn't exist
Returns
TypeDescrição
anyValue at key or fallback if key doesn't exist

See also GetAllValuesKeys, SetValue.

SetValueOptimal​

Sets a Value in this Entity

Sets a value in this Entity, which can be accessed by any package (optionally sync on clients if called from server)

Please refer to Entity Values for more information

my_entity:SetValue(key, value, sync_on_clients?)
Parameters
NameTypeDescrição
keystringThe key
valueanyThe value, can be any serializable type (not functions)
sync_on_clients?booleanServer side parameter, if enabled will sync this value with all clients Default false

See also GetAllValuesKeys, GetValue.

Eventsfunctions​

SubscribeOptimal​

Subscribes to an Event on this specific entity

local ret = my_entity:Subscribe(event_name, callback)
Parameters
NameTypeDescrição
event_namestringName of the event to subscribe to
callbackfunctionFunction to call when the event is triggered
Returns
TypeDescrição
functionCallback that was passed (useful for unsubscribing later if your callback is an anonymous function)

UnsubscribeOptimal​

Unsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed

my_entity:Unsubscribe(event_name, callback?)
Parameters
NameTypeDescrição
event_namestringName of the event to unsubscribe from
callback?functionOptional callback to unsubscribe Default nil

Lifecyclefunctions​

DestroyModerate​

Destroys this Entity

my_entity:Destroy()

FinishSpawnModerate​

Finish the spawning process and send the entity to clients if it was spawned with a deferred spawn_mode

Finish the spawning process and send the entity to clients if it was spawned with SpawnMode.AfterConstructor or SpawnMode.Manual. Call this after configuring the entity for efficient spawning.

Note: an Entity of an Inherited Class constructed with SpawnMode.AfterConstructor finishes spawning automatically when its Constructor returns

my_entity:FinishSpawn()

IsBeingDestroyedOptimal​

Returns true if this Entity is being destroyed

You can check this inside events like Drop to see if a Pickable is being dropped because it's going to be destroyed

local ret = my_entity:IsBeingDestroyed()
Returns
TypeDescrição
booleanWhether this Entity is being destroyed

IsSpawnedOptimal​

Gets if this Entity finished spawning

An Entity spawned with a deferred SpawnMode is only spawned after FinishSpawn() is called on it or when the Inherited Class constructor returns, everything else is spawned right away

local ret = my_entity:IsSpawned()
Returns
TypeDescrição
booleanIf the Entity finished spawning

IsValidOptimal​

Returns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity)

local is_valid = my_entity:IsValid()
Returns
TypeDescrição
booleanWhether this Entity is valid

SetSpawnModeOptimal​

Overrides when this Entity finishes spawning, from the Constructor of an Inherited Class

Overrides when this Entity finishes spawning, from the Constructor of an Inherited Class.

Only SpawnMode.AfterConstructor and SpawnMode.Manual are accepted, and only while the Entity has not finished spawning yet

my_entity:SetSpawnMode(spawn_mode)
Parameters
NameTypeDescrição
spawn_modeSpawnModeOnly SpawnMode.AfterConstructor and SpawnMode.Manual are accepted

Networkfunctions​

BroadcastRemoteEventModerate​

Calls a custom remote event directly on this entity to all Players

🆕Updated Function
This method was recently updated in ver. 1.139. See the Compatibility Versions page for more information.
my_entity:BroadcastRemoteEvent(event_name, reliability?, args...?)
Parameters
NameTypeDescrição
event_namestringThe Event Name to trigger the event
reliability?ReliabilityThe network reliability rule Default Reliability.Reliable
args...?anyArguments to pass to the event Default nil

BroadcastRemoteInRadiusEventModerate​

Calls a custom remote event directly on this entity to all Players in a radius

my_entity:BroadcastRemoteInRadiusEvent(event_name, radius, reliability?, args...?)
Parameters
NameTypeDescrição
event_namestringThe Event Name to trigger the event
radiusfloatThe radius to send this event
reliability?ReliabilityThe network reliability rule Default Reliability.Reliable
args...?anyArguments to pass to the event Default nil

CallRemoteEventModerate​

Calls a custom remote event directly on this entity to a specific Player

🆕Updated Function
This method was recently updated in ver. 1.139. See the Compatibility Versions page for more information.
my_entity:CallRemoteEvent(event_name, player, reliability?, args...?)
Parameters
NameTypeDescrição
event_namestringThe Event Name to trigger the event
playerPlayerThe remote player to send this event
reliability?ReliabilityThe network reliability rule Default Reliability.Reliable
args...?anyArguments to pass to the event Default nil

CallRemoteEventModerate​

Calls a custom remote event directly on this entity

🆕Updated Function
This method was recently updated in ver. 1.139. See the Compatibility Versions page for more information.
my_entity:CallRemoteEvent(event_name, reliability?, args...?)
Parameters
NameTypeDescrição
event_namestringThe Event Name to trigger the event
reliability?ReliabilityThe network reliability rule Default Reliability.Reliable
args...?anyArguments to pass to the event Default nil

CallRemotePlayersEventModerate​

Calls a custom remote event directly on this entity to a list of Players

my_entity:CallRemotePlayersEvent(event_name, players, reliability?, args...?)
Parameters
NameTypeDescrição
event_namestringThe Event Name to trigger the event
playerstable of PlayerThe remote players to send this event
reliability?ReliabilityThe network reliability rule Default Reliability.Reliable
args...?anyArguments to pass to the event Default nil

HasAuthorityOptimal​

Gets if the local context has authority over this Entity (true if spawned by the client, false if spawned by the server)

local ret = my_entity:HasAuthority()
Returns
TypeDescrição
booleantrue if spawned by the client, false if spawned by the server

SubscribeRemoteOptimal​

Subscribes to a custom event called from server on this specific entity

local ret = my_entity:SubscribeRemote(event_name, callback)
Parameters
NameTypeDescrição
event_namestringName of the event to subscribe to
callbackfunctionFunction to call when the event is triggered
Returns
TypeDescrição
functionCallback that was passed (useful for unsubscribing later if your callback is an anonymous function)

Queriesfunctions​

GetIDOptimal​

Gets the universal network ID of this Entity (same on both client and server)

local id = my_entity:GetID()
Returns
TypeDescrição
integerUniversal network ID of this Entity

🚀 Events​

ClassRegisterTriggered when a new Class is registered with the Inheriting System
DestroyTriggered when an Entity is destroyed
SpawnTriggered when an Entity is spawned/created
ValueChangeTriggered when an Entity has a value changed with :SetValue()

ClassRegister​

Triggered when a new Class is registered with the Inheriting System

<AnyEntityClass>.Subscribe("ClassRegister", function(class)
-- ClassRegister was called
end)
Arguments
NameTypeDescrição
classtableThe inherited Class

Destroy​

Triggered when an Entity is destroyed

<AnyEntityClass>.Subscribe("Destroy", function(self)
-- Destroy was called
end)
Arguments
NameTypeDescrição
selfBase EntityThe Entity which that was destroyed

Spawn​

Triggered when an Entity is spawned/created

<AnyEntityClass>.Subscribe("Spawn", function(self)
-- Spawn was called
end)
Arguments
NameTypeDescrição
selfBase EntityThe Entity that was spawned

ValueChange​

Triggered when an Entity has a value changed with :SetValue()

<AnyEntityClass>.Subscribe("ValueChange", function(self, key, value)
-- ValueChange was called
end)
Arguments
NameTypeDescrição
selfBase EntityThe Entity that just had a value changed
keystringThe key used
valueanyThe value that was set