📦 Package
Class which represents the current Package
🗿Static Class
This is a Static Class. Access it's methods directly with
.. It's not possible to spawn new instances.🧑💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!
🗿 Static Functions
| Returns | Name | Description | |
|---|---|---|---|
Export | Makes any variable available in the global scope | ||
FlushPersistentData | Flushes the Persistent Data pending changes to disk immediately | ||
| string | GetCompatibilityVersion | Returns the package compatibility version | |
| table of string | GetDirectories | Gets a list of all directories in this package | |
| table of string | GetFiles | Gets a list of all files in this package | |
| string | GetName | Returns the package name/path | |
| table | GetPersistentData | Gets the Persistent Value from the disk | |
| string | GetTitle | Returns the package title | |
| string | GetVersion | Returns the package version | |
| boolean | IsUnloading | Returns whether this package is currently unloading | |
| function | LoadFile | 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 | ||
| any | Require | Loads a .lua file | |
SetPersistentData | Sets a Persistent Value which will be saved to disk | ||
| function | Subscribe | 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 |

Export
Makes any variable available in the global scope
Package.Export(variable_name, value)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | variable_name | Required parameter | Name of the variable to export |
| any | value | Required parameter | Value to be set in the global scope |

FlushPersistentData
Flushes the Persistent Data pending changes to disk immediately
Package.FlushPersistentData()

GetCompatibilityVersion
Returns the package compatibility version
local ret = Package.GetCompatibilityVersion()
Returns
| Type | Description |
|---|---|
| string | The package compatibility version |

GetDirectories
Gets a list of all files in this package, optionally with filters
local ret = Package.GetDirectories(path_filter?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | path_filter? | | Filtre de chemins |

GetFiles
Gets a list of all files in this package, optionally with filters
local ret = Package.GetFiles(path_filter?, extension_filter?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string or table | path_filter? | | Filtre de chemins |
| string | extension_filter? | | Example: .lua |

GetName
Returns the package name/path
local ret = Package.GetName()
Returns
| Type | Description |
|---|---|
| string | The package name/path |

GetPersistentData
Gets the Persistent Value from the disk
local ret = Package.GetPersistentData(key?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | key? | | The key to get the data |
Returns
| Type | Description |
|---|---|
| table | Persistent values from disk |
See also SetPersistentData.

GetTitle
Returns the package title
local ret = Package.GetTitle()
Returns
| Type | Description |
|---|---|
| string | The package title |

GetVersion
Returns the package version
local ret = Package.GetVersion()
Returns
| Type | Description |
|---|---|
| string | The package version |

IsUnloading
Returns whether this package is currently unloading
local ret = Package.IsUnloading()
Returns
| Type | Description |
|---|---|
| boolean | No description provided |

LoadFile
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
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | file_path | Required parameter | Path to the script file to compile |
Returns
| Type | Description |
|---|---|
| function | the compiled function to run the script, allowing you to pass a environment env table for the script with this format |
Package.LoadFile Examples
Loading a .lua file sandboxed
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.

ReloadClientFile
Reloads a file fromClient/orShared/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
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | file_path | Required parameter | The file path relative to the package root |
See also FileReload.

Require
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/andShared/folders.
local ret = Package.Require(file_path, force_load?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | file_path | Required parameter | Path to the script file to load |
| boolean | force_load? | false | Whether to force loading this file even if it was already loaded |
Returns
| Type | Description |
|---|---|
| any | any return values from the included file |
See also LoadFile.

SetPersistentData
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
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | key | Required parameter | Key to index data into. It can be separated by '.' to set a child element. |
| any | value | Required parameter | Value to set at the key |
See also GetPersistentData.

Subscribe
Subscribes to an Event
local ret = Package.Subscribe(event_name, callback)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | Event to subscribe to |
| function | callback | Required parameter | Callback to run on the event occurring |
Returns
| Type | Description |
|---|---|
| function | The function callback |

Unsubscribe
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?)
Parameters
| Type | Parameter | Default | Description |
|---|---|---|---|
| string | event_name | Required parameter | Event to unsubscribe to |
| function | callback? | nil | Optional callback to specifically unsubscribe to |
🚀 Events
| Name | Description | |
|---|---|---|
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
| Type | Argument | Description |
|---|---|---|
| string | file_path | 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)