Roblox Functions and Variables
Roblox Functions and Variables
Roblox has several unique functions and variables built into its Lua implementation. These are only found on Roblox and are not packaged by default with Lua.
Functions
delay
void delay(number delayTime, function callback)
Schedules a function to be executed after delayTime seconds have passed, without yielding the current thread. This function allows multiple Lua threads to be executed in parallel from the same stack. The delay will have a minimum duration of 29 milliseconds, but this minimum may be higher depending on the target framerate and various throttling conditions. If the delayTime parameter is not specified, the minimum duration will be used.
DebuggerManager
DebuggerManager DebuggerManager()
Returns the DebuggerManager
class, which acts as an interface for Roblox’s Lua debugger feature.
elapsedTime
number elapsedTime()
Returns how much time has elapsed since the current instance of Roblox was started. In Roblox Studio, this begins counting up from the moment Roblox Studio starts running, not just when opening a place.
LoadLibrary
RbxLibrary LoadLibrary(string libraryName)
Returns a built-in Roblox library, based on the libraryName specified: RbxGui, RbxUtility, or RbxStamper. These libraries are not documented here since LoadLibrary is deprecated.
PluginManager
PluginManager PluginManager()
Returns the PluginManager
which is a deprecated singleton that was previously required to create plugins. It still has applicable uses, such as if you need to create a Plugin object from Roblox Studio’s command bar.
printidentity
void printidentity()
Prints Current identity is [ID]
to the output, where [ID] corresponds to the current thread’s security context level.
require
Variant require(Variant<ModuleScript,int64> module)
Runs the supplied ModuleScript
if it has not been run already, and returns what the ModuleScript returned (in both cases). If the ModuleScript the user wants to use has been uploaded to Roblox (with the instance’s name being ‘MainModule’), it can be loaded by using the require function on the asset ID of the ModuleScript, though only on the server.
settings
GlobalSettings settings()
Returns the GlobalSettings
object, which can be used to access the settings objects that are used in Roblox Studio’s settings menu.
spawn
void spawn(function callback)
Runs the specified callback function in a separate thread, without yielding the current thread. The function will be executed the next time Roblox’s Task Scheduler runs an update cycle. This delay will take at least 29 milliseconds but can arbitrarily take longer, depending on the target framerate and various throttling conditions.
stats
void stats()
Returns the Stats
service. It is preferred that developers use ServiceProvider/GetService
to retrieve it instead.
tick
number tick()
Returns the amount of time in seconds since the UNIX epoch (January 1st, 1970) on the current local session’s computer. It is precise to the nearest millisecond (0.001s).
time
number time()
Returns the amount of time in seconds since the current game instance started running. If the current game instance is not running, this will be 0.
typeof
string typeof(Variant object)
Returns the type of the given object as a string. This function works similarly to Lua’s native type function, with the exceptions that Roblox-defined data types like Vector3 and CFrame return their respective data types as strings.
UserSettings
UserSettings UserSettings()
Returns the UserSettings
object, which is used to read information from the current user’s game menu settings.
version
void version()
Returns the current version of Roblox as a string. The integers in the version string are separated by periods, and each integers represent the following, in order:
- Generation - The current generation of the application shell that is hosting the client.
- Version - The current release version of Roblox.
- Patch - The current patch number for this version of Roblox.
- Commit - The ID of the last internal commit that was accepted into this version of the client.
wait
number, number wait(number seconds = 0.03)
Yields the current thread until the specified amount of seconds have elapsed. The delay will have a minimum duration of 29 milliseconds, but this minimum may be higher depending on the target framerate and various throttling conditions. If the seconds parameter is not specified, the minimum duration will be used.
warn
void warn(Tuple params)
Behaves identically to Lua’s print function, except the output is styled as a warning, with yellow text and a timestamp. This function accepts any number of arguments, and will attempt to convert them into strings which will then be joined together with spaces between them.
Variables
Enum
Enums Enum
A reference to the Enums
datatype, which stores all of the available enums that can be used on Roblox.
game
DataModel game
A reference to the DataModel
, which is the root Instance of Roblox’s parent/child hierarchy.
plugin
Plugin plugin
A reference to the Plugin
object that represents the plugin being ran from this Script
. This reference only exists in the context where a script is executed as a plugin.
shared
table shared
A table that is shared across all scripts that share the same execution context level. This serves the exact same purpose as _G.
script
LuaSourceContainer script
A reference to the script object that is executing the code you are writing. It can be either a Script
, a LocalScript
, or a ModuleScript
(and sometimes a CoreScript
). This variable is not available when executing code from Roblox Studio’s command bar.
workspace
Workspace workspace
A reference to the Workspace
service, which contains all of the physical components of a Roblox world.