Skip to content

Script

ScriptComponent is the base class for all user created scripts. Within a script function it is accessed through the self local variable.

Functions

Function Name Usage Description Notes
GetProperties Properties scriptComponent:GetProperties() Alternative to self.properties, this gets the bag of values produced from the property
editor for this script on this Entity. The properties are defined by the static Properties
table on the table returned by the Lua script.
RevertClientProperty scriptComponent:RevertClientProperty(string propertyName) Revert a property that's been changed on the client back to the server's value for it Client Only
GetEntity Entity scriptComponent:GetEntity() Returns the Entity that the script is attached to.
GetScriptAsset ScriptAsset scriptComponent:GetScriptAsset() Returns the ScriptAsset this is an instance of.
ListenForEvent scriptComponent:ListenForEvent(string eventName, Script listenerScriptComponent) Tell this script that listenerScriptComponent wants to be informed when it sounds eventName
using SendEventToListeners. eventName will be called on the listenerScriptComponent script.
ListenForEvent scriptComponent:ListenForEvent(string eventName, Script listenerScriptComponent, string functionName) Tell this script that listenerScriptComponent wants to be informed when it sounds eventName
using SendEventToListeners. functionName will be called on the listenerScriptComponent script.
SendEventToListeners scriptComponent:SendEventToListeners(string eventName, ... args) Call eventName on any scripts that have registered for it using ListenForEvent with the given args.
If called on the server do it only on the server, if called on a client do it only on that client.
Schedule ScheduleHandle scriptComponent:Schedule(callback function) Pass this a function to do that function in a thread. Can use globals like Wait to control flow as the
function will be re-entrant. Returns a Handle which can be passed to Cancel
Cancel scriptComponent:Cancel(ScheduleHandle handle) Cancel a scheduled task if its running.
SetSaveData scriptComponent:SetSaveData(table saveTable) Set the save data for this script to the table supplied. The script must be owned by a User or Player. Server Only
GetSaveData scriptComponent:GetSaveData(callback callback) Get the save data previously written out with SetSaveData on this script. This function
is asynchronous and will call the callback function when its finished with the save data
as an argument. Deprecated, Server Only
GetSaveData object scriptComponent:GetSaveData() Get the save data previously written out with SetSaveData on this script. This function
returns the save data immediately. Server Only
SendToScript scriptComponent:SendToScript(string eventName, ... args) Call eventName on this script if it exists, with the given args.
SendToAllClients scriptComponent:SendToAllClients(string eventName, ... args) Call eventName on this script on all clients currently connected to the server with the given args.
Note, this function call can not guarantee that entities are all in a ready state on the client at the time of call,
and might therefore miss events during construction. Server Only
SendToServer scriptComponent:SendToServer(string eventName, ... args) Call eventName on this script on the server. Local Only
SendToLocal scriptComponent:SendToLocal(string eventName, ... args) Call eventName on this script on the client that owns the Player or User this script is
attached to. Server Only

Overrides

Override Name Usage Description Notes
new_index script.var = object value

Entry Points

Entry Point Name Usage Description Notes
OnInteract function Script:OnInteract(Entity player, HitResult hitResult) ... end Called when a player interacts with an entity on all scripts of the entity. Server Only
OnCollision function Script:OnCollision(Entity collidingPlayerOrEntity) ... end Called when a player collides with an entity on all scripts of the entity.
Also calls this function on the player's scripts with the entity as the argument. Server Only
OnDamage function Script:OnDamage(number damageAmount, Entity damageCauser, HitResult hitResult) ... end Called when an entity is damaged on all scripts of the entity. Server Only
Init function Script:Init() ... end Called to initialize a script on the server. Server Only
ClientInit function Script:ClientInit() ... end Called to initialize a script on the client. Client Only
LocalInit function Script:LocalInit() ... end Called to initialize a script on the client that controls this entity (eg player, user, etc...) Local Only
OnTick function Script:OnTick(number deltaTimeSeconds) ... end Called each frame on the server. Server Only
ClientOnTick function Script:ClientOnTick(number deltaTimeSeconds) ... end Called each frame on the client. Client Only
LocalOnTick function Script:LocalOnTick(number deltaTimeSeconds) ... end Called each frame on the client that controls this entity (eg player, user, etc...) Local Only
OnUserLogin function Script:OnUserLogin(User user) ... end Called when a new user joins the game. Server Only
OnUserLogout function Script:OnUserLogout(User user) ... end Called when a new user leaves the game. Server Only
OnDeathPlaneTrigger function Script:OnDeathPlaneTrigger() ... end Called by the game on a Player when
the Player is below the death plane
setting Server Only
OnTriggerEnter function Script:OnTriggerEnter(Entity other) ... end Called by a trigger component when
an entity enters the trigger volume Server Only
OnTriggerExit function Script:OnTriggerExit(Entity other) ... end Called by a trigger component when
an entity exits the trigger volume Server Only
OnButtonPressed function Script:OnButtonPressed(string buttonName) ... end Called on player and user scripts when a particular button is pressed, giving the string name of the button Server Only
OnButtonReleased function Script:OnButtonReleased(string buttonName) ... end Called on player and user scripts when a particular button is released, giving the string name of the button Server Only
OnIronSightStart function Script:OnIronSightStart() ... end Called when the character goes in to Iron Sight mode Server Only
OnIronSightStop function Script:OnIronSightStop() ... end Called when the character stops Iron Sight mode Server Only
OnSprintStart function Script:OnSprintStart() ... end Called when the character starts sprinting Server Only
OnSprintStop function Script:OnSprintStop() ... end Called when the character stops sprinting Server Only
OnCrouch function Script:OnCrouch() ... end Called when the character crouches Server Only
OnStand function Script:OnStand() ... end Called when the character stands from crouch Server Only
OnJump function Script:OnJump() ... end Called on the player when a jump action happened Server Only
LocalOnButtonPressed function Script:LocalOnButtonPressed(string buttonName) ... end Called locally on player and user scripts when a particular button is pressed, giving the string name of the button Local Only
LocalOnButtonReleased function Script:LocalOnButtonReleased(string buttonIndex) ... end Called locally on player and user scripts when a particular button is released, giving the string name of the button Local Only
LocalOnIronSightStart function Script:LocalOnIronSightStart() ... end Called when the character goes in to Iron Sight mode Local Only
LocalOnIronSightStop function Script:LocalOnIronSightStop() ... end Called when the character stops Iron Sight mode Local Only
LocalOnSprintStart function Script:LocalOnSprintStart() ... end Called when the character starts sprinting Local Only
LocalOnSprintStop function Script:LocalOnSprintStop() ... end Called when the character stops sprinting Local Only
LocalOnCrouch function Script:LocalOnCrouch() ... end Called when the character crouches Local Only
LocalOnStand function Script:LocalOnStand() ... end Called when the character stands from crouch Local Only
LocalOnJump function Script:LocalOnJump() ... end Called on the player when a jump action happened Local Only
OnHotbarChanged function Script:OnHotbarChanged(number hotbarIndex) ... end Called on server when the user's hotbar index changes, either by using the previous and next buttons
or using the hotbar keys on a keyboard. Calls function on all user and player scripts. Server Only
OnChatMessage function Script:OnChatMessage(User user, Text message) ... end Called when a quick chat message is triggered by a user Client Only
OnDestroy function Script:OnDestroy() ... end Called on the server when an entity is destroyed Server Only
LocalOnMantleStart function Script:LocalOnMantleStart() ... end Called when the character starts to mantle up to a platform Local Only
OnMantleStart function Script:OnMantleStart() ... end Called when the character starts to mantle up to a platform Server Only
LocalOnMantleStop function Script:LocalOnMantleStop() ... end Called when the character stops to mantling up to a platform Local Only
OnMantleStop function Script:OnMantleStop() ... end Called when the character stops to mantling up to a platform Server Only
LocalOnSlideStart function Script:LocalOnSlideStart() ... end Called when the character starts to slide Local Only
OnSlideStart function Script:OnSlideStart() ... end Called when the character starts to slide Server Only
LocalOnSlideStop function Script:LocalOnSlideStop() ... end Called when the character stops sliding Local Only
OnSlideStop function Script:OnSlideStop() ... end Called when the character stops sliding Server Only
LocalOnRollStart function Script:LocalOnRollStart() ... end Called when the character starts to roll Local Only
OnRollStart function Script:OnRollStart() ... end Called when the character starts to roll Server Only
LocalOnRollStop function Script:LocalOnRollStop() ... end Called when the character stops rolling Local Only
OnRollStop function Script:OnRollStop() ... end Called when the character stops rolling Server Only
LocalOnSpawnEffectEnded function Script:LocalOnSpawnEffectEnded() ... end Called when the character spawn effect has ended Local Only
OnSpawnEffectEnded function Script:OnSpawnEffectEnded() ... end Called when the character spawn effect has ended Server Only
OnActivityTriggered function Script:OnActivityTriggered(string id, text display, string category) ... end Called when an activity is triggered