📦 Package
Class which represents the current Package
🗿 Static Functions
| Data | ||
FlushPersistentData | Flushes the Persistent Data pending changes to disk immediately | |
GetPersistentData: table | Gets the Persistent Value from the disk | |
SetPersistentData | Sets a Persistent Value which will be saved to disk | |
| Lifecycle | ||
IsUnloading: boolean | Returns whether this package is currently unloading | |
Subscribe: function | Subscribes to an Event | |
Unsubscribe | Unsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback | |
| Metadata | ||
GetCompatibilityVersion: string | Returns the package compatibility version | |
GetName: string | Returns the package folder name | |
GetTitle: string | Returns the package title | |
GetVersion: string | Returns the package version | |
| Scripting | ||
Export | Makes any variable available in the global scope | |
GetDirectories: table of string | Gets a list of all directories in this package | |
GetFiles: table of string | Gets a list of all files in this package | |
LoadFile: function | Compiles a .lua file and returns a function to run it | |
ReloadClientFile | Reloads a file from Client/ or Shared/ folder and sends the updated version to clients, triggering the FileReload event on them | |
Require: any | Loads a .lua file | |
Datastatic functions

FlushPersistentDataSlow
Flushes the Persistent Data pending changes to disk immediately
Note: this operation is already performed automatically under the hood, it is not necessary to keep always flushing and should only be used when really needed, as disk writing is a slow operation
Package.FlushPersistentData()

GetPersistentDataSlow
Gets the Persistent Value from the disk
Gets a Persistent Value from the disk
Pass no parameter to return the whole table, or a key to get a specific value
local ret = Package.GetPersistentData(key?)
Parameters
| Name | Type | Descrição |
|---|---|---|
key? | string | The key to get the data Default |
Returns
| Type | Descrição |
|---|---|
| table | Persistent values from disk |
See also SetPersistentData.

SetPersistentDataModerate
Sets a Persistent Value which will be saved to disk
Note the actual flush to disk is deferred and may not occur immediately
Package.SetPersistentData(key, value)
Parameters
| Name | Type | Descrição |
|---|---|---|
key | string | Key to index data into. It can be separated by '.' to set a child element |
value | any | Value to set at the key |
See also GetPersistentData.
Lifecyclestatic functions

IsUnloadingOptimal
Returns whether this package is currently unloading
local ret = Package.IsUnloading()
Returns
| Type | Descrição |
|---|---|
| boolean | Whether this package is currently unloading |

SubscribeOptimal
Subscribes to an Event
local ret = Package.Subscribe(event_name, callback)
Parameters
| Name | Type | Descrição |
|---|---|---|
event_name | string | Event to subscribe to |
callback | function | Callback to run on the event occurring |
Returns
| Type | Descrição |
|---|---|
| function | The function callback |

UnsubscribeOptimal
Unsubscribes from all subscribed Events in this Class and in this Package, optionally passing the function to unsubscribe only that callback
Package.Unsubscribe(event_name, callback?)
Metadatastatic functions

GetCompatibilityVersionOptimal
Returns the package compatibility version
local ret = Package.GetCompatibilityVersion()
Returns
| Type | Descrição |
|---|---|
| string | The package compatibility version |

GetNameOptimal
Returns the package folder name
local ret = Package.GetName()
Returns
| Type | Descrição |
|---|---|
| string | The package name/path |

GetTitleOptimal
Returns the package title
local ret = Package.GetTitle()
Returns
| Type | Descrição |
|---|---|
| string | The package title |

GetVersionOptimal
Returns the package version
local ret = Package.GetVersion()
Returns
| Type | Descrição |
|---|---|
| string | The package version |
Scriptingstatic functions

GetDirectoriesSlow
Gets a list of all directories in this package
Gets a list of all files in this package, optionally with filters
local ret = Package.GetDirectories(path_filter?)
Parameters
| Name | Type | Descrição |
|---|---|---|
path_filter? | string | Path filter Default |

GetFilesSlow
Gets a list of all files in this package
Filters are optional
local ret = Package.GetFiles(path_filter?, extension_filter?)

LoadFileSlow
Compiles a .lua file and returns a function to run it
To be used for loading files in a sandboxed environment.
Supports the same searchers as Package.Require
local ret = Package.LoadFile(file_path)
Parameters
| Name | Type | Descrição |
|---|---|---|
file_path | string | Path to the script file to compile |
Returns
| Type | Descrição |
|---|---|
| function | the compiled function to run the script, allowing you to pass an environment table for the script with this format |
Examples (1)
local func = Package.LoadFile("MyScript.lua")
-- Only allows this file to access Console
local my_env = { Console = Console }
local content = func(my_env)
-- Access all global variables set by the script in my_env
my_env.GlobalVariableFromFile...
See also Require.

ReloadClientFileSlow
Reloads a file from Client/ or Shared/ folder and sends the updated version to clients, triggering the FileReload event on them
The reloaded file will be re-cached and downloaded normally by new connecting clients
Note that this method does use the main network lane, so it is not recommended to be used frequently or with large files in production environments as it may cause network congestion and lag spikes. It is mostly intended for development purposes to allow faster iteration on client files without needing to reload the whole package
Package.ReloadClientFile(file_path)
Parameters
| Name | Type | Descrição |
|---|---|---|
file_path | string | The file path relative to the package root |
See also FileReload.

RequireSlow
Loads a .lua file
Note that this method caches the result, so further calls return the cached value.
We currently support 5 searchers, which are looked in the following order:
- Relative to
current-file-path/ - Relative to
current-package/Client/orcurrent-package/Server/(depending on your side) - Relative to
current-package/Shared/ - Relative to
current-package/ - Relative to
Packages/
Note: Clients will only download and have access to Client/ and Shared/ folders.
local ret = Package.Require(file_path, force_load?)
Parameters
| Name | Type | Descrição |
|---|---|---|
file_path | string | Path to the script file to load |
force_load? | boolean | Whether to force loading this file even if it was already loaded Default false |
Returns
| Type | Descrição |
|---|---|
| any | any return values from the included file |
See also LoadFile.
🚀 Events
FileReload | Called when a file is directly reloaded from the server using Package.ReloadClientFile() | |
Load | Called when this package is loaded | |
Unload | Called when this package is unloaded |

FileReload
Called when a file is directly reloaded from the server using Package.ReloadClientFile()
You can use the path to reload the file in runtime with Package.Require(path, true)
Package.Subscribe("FileReload", function(file_path)
-- FileReload was called
end)
Arguments
| Name | Type | Descrição |
|---|---|---|
file_path | string | The file path |
See also ReloadClientFile.

Load
Called when this package is loaded
This event is triggered differently depending on the situation:
- When the server starts or you run
package reload allthe event triggers only after ALL packages are loaded. - In all other cases (
package load/reloadorPackage.Load/Reload) the event is triggered immediately after the package is loaded/reloaded.
Package.Subscribe("Load", function()
-- Load was called
end)

Unload
Called when this package is unloaded
Package.Subscribe("Unload", function()
-- Unload was called
end)


