Skip to main content
Version: latest - a1.148.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
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, 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โ€‹

ReturnsNameDescription
table of Base EntityGetAllReturns a table containing all Entities of the class this is called on
Base EntityGetByIndexReturns a specific Entity of this class at an index
integerGetCountReturns how many Entities of this class exist
table of tableGetInheritedClassesGets a list of all directly inherited classes from this Class created with the Inheriting System
iteratorGetPairsReturns an iterator with all Entities of this class to be used with pairs()
table or nilGetParentClassGets the parent class if this Class was created with the Inheriting System
tableInheritInherits this class with the Inheriting System
booleanIsChildOfGets if this Class is child of another class if this Class was created with the Inheriting System
functionSubscribeSubscribes to an Event for all entities of this Class
functionSubscribeRemoteSubscribes to a custom event called from server
UnsubscribeUnsubscribes all callbacks from this Event in this Class within this Package, or only the callback passed

Moderate

GetAllโ€‹

Returns a table containing all Entities of the class this is called on
local ret = <AnyEntityClass>.GetAll()

Returns

TypeDescription
table of Base EntityCopy of table containing all Entities

Optimal

GetByIndexโ€‹

Returns a specific Entity of this class at an index
local ret = <AnyEntityClass>.GetByIndex(index)

Parameters

TypeParameterDefaultDescription
integerindex Required parameter The index of the Entity

Returns

TypeDescription
Base EntityEntity at index

Optimal

GetCountโ€‹

Returns how many Entities of this class exist
local ret = <AnyEntityClass>.GetCount()

Returns

TypeDescription
integerNumber of Entities of this class

Moderate

GetInheritedClassesโ€‹

Gets a list of all directly inherited classes from this Class created with the Inheriting System
local ret = <AnyEntityClass>.GetInheritedClasses(recursively?)

Parameters

TypeParameterDefaultDescription
booleanrecursively?false
Returns all inherited children

Returns

TypeDescription
table of tableAll children Classes

Optimal

GetPairsโ€‹

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

TypeDescription
iteratorIterator with all Entities of this class

Optimal

GetParentClassโ€‹

Gets the parent class if this Class was created with the Inheriting System
local ret = <AnyEntityClass>.GetParentClass()

Returns

TypeDescription
table or nilThe parent class

Slow

Inheritโ€‹

Inherits this class with the Inheriting System
local class = <AnyEntityClass>.Inherit(name, custom_values?)

Parameters

TypeParameterDefaultDescription
stringname Required parameter The name of the new Class
tablecustom_values?{}
An optional table with custom values to be set in the inherited class table

Returns

TypeDescription
tableThe new Class table

Optimal

IsChildOfโ€‹

Gets if this Class is child of another class if this Class was created with the Inheriting System
local ret = <AnyEntityClass>.IsChildOf(class)

Parameters

TypeParameterDefaultDescription
tableclass Required parameter The other class to check

Returns

TypeDescription
booleanNo description provided

Optimal

Subscribeโ€‹

Subscribes to an Event for all entities of this Class
local ret = <AnyEntityClass>.Subscribe(event_name, callback)

Parameters

TypeParameterDefaultDescription
stringevent_name Required parameter Name of the event to subscribe to
functioncallback Required parameter Function to call when the event is triggered

Returns

TypeDescription
functionCallback that was passed (useful for unsubscribing later if your callback is an anonymous function)

Optimal

SubscribeRemoteโ€‹

Subscribes to a custom event called from server
local ret = <AnyEntityClass>.SubscribeRemote(event_name, callback)

Parameters

TypeParameterDefaultDescription
stringevent_name Required parameter Name of the event to subscribe to
functioncallback Required parameter Function to call when the event is triggered

Returns

TypeDescription
functionCallback that was passed (useful for unsubscribing later if your callback is an anonymous function)

Optimal

Unsubscribeโ€‹

Unsubscribes all callbacks from this Event in this Class within this Package, or only the callback passed
<AnyEntityClass>.Unsubscribe(event_name, callback?)

Parameters

TypeParameterDefaultDescription
stringevent_name Required parameter Name of the event to unsubscribe from
functioncallback?nil
Optional callback to unsubscribe

๐Ÿฆ ย Functionsโ€‹

ReturnsNameDescription
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
DestroyDestroys this Entity
FinishSpawnFinish the spawning process and send the entity to clients if it was spawned with defer_spawn
table of stringGetAllValuesKeysGets a list of all values keys
tableGetClassGets the class of this entity
integerGetIDGets the universal network ID of this Entity (same on both client and server)
anyGetValueGets a Value stored on this Entity at the given key
booleanHasAuthorityGets if the local context has authority over this Entity (true if spawned by the client, false if spawned by the server)
booleanIsARecursively checks if this entity is inherited from a Class
booleanIsBeingDestroyedReturns true if this Entity is being destroyed
booleanIsValidReturns true if this Entity is valid (i.e. wasn't destroyed and points to a valid Entity)
SetValueSets a Value in this Entity
functionSubscribeSubscribes to an Event on this specific entity
functionSubscribeRemoteSubscribes to a custom event called from server on this specific entity
UnsubscribeUnsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed

Moderate

BroadcastRemoteEventโ€‹

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

TypeParameterDefaultDescription
stringevent_name Required parameter The Event Name to trigger the event
Reliabilityreliability?Reliability.Reliable
The network reliability rule
anyargs...?nil
Arguments to pass to the event

Moderate

BroadcastRemoteInRadiusEventโ€‹

Calls a custom remote event directly on this entity to all Players in a radius
my_entity:BroadcastRemoteInRadiusEvent(event_name, radius, reliability?, args...?)

Parameters

TypeParameterDefaultDescription
stringevent_name Required parameter The Event Name to trigger the event
floatradius Required parameter The radius to send this event
Reliabilityreliability?Reliability.Reliable
The network reliability rule
anyargs...?nil
Arguments to pass to the event

Moderate

CallRemoteEventโ€‹

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

TypeParameterDefaultDescription
stringevent_name Required parameter The Event Name to trigger the event
Playerplayer Required parameter The remote player to send this event
Reliabilityreliability?Reliability.Reliable
The network reliability rule
anyargs...?nil
Arguments to pass to the event

Moderate

CallRemoteEventโ€‹

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

TypeParameterDefaultDescription
stringevent_name Required parameter The Event Name to trigger the event
Reliabilityreliability?Reliability.Reliable
The network reliability rule
anyargs...?nil
Arguments to pass to the event

Moderate

CallRemotePlayersEventโ€‹

Calls a custom remote event directly on this entity to a list of Players
my_entity:CallRemotePlayersEvent(event_name, players, reliability?, args...?)

Parameters

TypeParameterDefaultDescription
stringevent_name Required parameter The Event Name to trigger the event
table of Playerplayers Required parameter The remote players to send this event
Reliabilityreliability?Reliability.Reliable
The network reliability rule
anyargs...?nil
Arguments to pass to the event

Moderate

Destroyโ€‹

Destroys this Entity
my_entity:Destroy()

Moderate

FinishSpawnโ€‹

Finish the spawning process and send the entity to clients if it was spawned with defer_spawn. Call this after configuring the entity for efficient spawning
my_entity:FinishSpawn()

Moderate

GetAllValuesKeysโ€‹

Gets a list of all values keys
local ret = my_entity:GetAllValuesKeys()

Returns

TypeDescription
table of stringa list with all values keys

See also GetValue, SetValue.


Optimal

GetClassโ€‹

Gets the class of this entity
local class = my_entity:GetClass()

Returns

TypeDescription
tableclass

Optimal

GetIDโ€‹

Gets the universal network ID of this Entity (same on both client and server)
local id = my_entity:GetID()

Returns

TypeDescription
integerid

Optimal

GetValueโ€‹

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

TypeParameterDefaultDescription
stringkey Required parameter No description provided
anyfallback Required parameter Fallback value if key doesn't exist

Returns

TypeDescription
anyValue at key or fallback if key doesn't exist

See also GetAllValuesKeys, SetValue.


Optimal

HasAuthorityโ€‹

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

TypeDescription
booleantrue if spawned by the client, false if spawned by the server

Moderate

IsAโ€‹

Recursively checks if this entity is inherited from a Class
local ret = my_entity:IsA(class)

Parameters

TypeParameterDefaultDescription
tableclass Required parameter The Class

Returns

TypeDescription
booleanNo description provided

Optimal

IsBeingDestroyedโ€‹

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

TypeDescription
booleanNo description provided

Optimal

IsValidโ€‹

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

TypeDescription
booleanis_valid

Optimal

SetValueโ€‹

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

TypeParameterDefaultDescription
stringkey Required parameter No description provided
anyvalue Required parameter No description provided
booleansync_on_clients?false
Server side parameter, if enabled will sync this value with all clients

See also GetAllValuesKeys, GetValue.


Optimal

Subscribeโ€‹

Subscribes to an Event on this specific entity
local ret = my_entity:Subscribe(event_name, callback)

Parameters

TypeParameterDefaultDescription
stringevent_name Required parameter Name of the event to subscribe to
functioncallback Required parameter Function to call when the event is triggered

Returns

TypeDescription
functionCallback that was passed (useful for unsubscribing later if your callback is an anonymous function)

Optimal

SubscribeRemoteโ€‹

Subscribes to a custom event called from server on this specific entity
local ret = my_entity:SubscribeRemote(event_name, callback)

Parameters

TypeParameterDefaultDescription
stringevent_name Required parameter Name of the event to subscribe to
functioncallback Required parameter Function to call when the event is triggered

Returns

TypeDescription
functionCallback that was passed (useful for unsubscribing later if your callback is an anonymous function)

Optimal

Unsubscribeโ€‹

Unsubscribes all callbacks from this Event in this Entity within this Package, or only the callback passed
my_entity:Unsubscribe(event_name, callback?)

Parameters

TypeParameterDefaultDescription
stringevent_name Required parameter Name of the event to unsubscribe from
functioncallback?nil
Optional callback to unsubscribe

๐Ÿš€ย Eventsโ€‹

NameDescription
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

TypeArgumentDescription
tableclassThe inherited Class

Destroyโ€‹

Triggered when an Entity is destroyed
<AnyEntityClass>.Subscribe("Destroy", function(self)
-- Destroy was called
end)

Arguments

TypeArgumentDescription
Base EntityselfThe Entity which that was destroyed

Spawnโ€‹

Triggered when an Entity is spawned/created
<AnyEntityClass>.Subscribe("Spawn", function(self)
-- Spawn was called
end)

Arguments

TypeArgumentDescription
Base EntityselfThe 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

TypeArgumentDescription
Base EntityselfThe Entity that just had a value changed
stringkeyThe key used
anyvalueThe value that was set