Global namespace/Roblox namespace

(Redirected from Tick())
< Global namespace

Roblox has several unique built-in APIs found in it's Lua environment. These are only found on Roblox, and are not packaged by default with Lua.

Variables[edit]

Variable Description
game A reference to the DataModel.pngDataModel, which is the root class of the parent-child hierarchy on Roblox.
Enum A static variable that lets you access all of Roblox's official enums, which are used with various APIs on Roblox.
plugin A variable that is only present when the code is being ran in a plugin. Represents the ExplorerImageIndex81.pngPlugin object associated with the plugin itself.
script A variable that is only present when the code is being ran by a Object Icon.pngLuaSourceContainer. This can be either a Script icon.pngScript, a Localscript icon.pngLocalScript or a ExplorerImageIndex76.pngModuleScript.
shared A table, that is shared with scripts of the same context level. This functions identically to the _G table.
workspace A reference to the Workspace icon.pngWorkspace, which is where all physically interactive objects are located.

Data Constructors[edit]

Name Description
Axes Allows you to specify what axes should be visible on an Archandles icon.pngArcHandles object.
BrickColor A list of roughly 200 pre-determined colors that you can apply to Object Icon.pngBaseParts.
CFrame A means of representing both position, and orientation, as well as relative space between objects.
Color3 Allows you to construct any color, with either RGB values, or HSV values.
ColorSequence Represents a sequence of Color3 values and times. Used with the ExplorerImageIndex80.pngParticleEmitter class.
ColorSequenceKeypoint Represents a keypoint in a ColorSequence.
Faces Allows you to specify what faces can be dragged with a Handles icon.pngHandles object.
Instance Allows you to construct most classes that are listed on the API Class reference.
NumberRange Represents a numerical range of values, between the specified Min/Max values.
NumberSequence Represents a sequence of changes to a numerical value over time.
NumberSequenceKeypoint Specifies a time, value, and envelope point in a NumberSequence.
PhysicalProperties Represents the physical properties of a Object Icon.pngBasePart, which can be changed using the CustomPhysicalProperties property.
Ray Represents a line starting at a 3D point, that travels infinitely in one direction. Used for raycasting.
Rect Represents a rectangular crop when using the SliceCenter GUI feature.
Region3 Represents a world-space bounding box, defined by two coordinates. Primarily used with Terrain.
Region3int16 Similar to Region3, but uses Vector3int16 coordinates instead of Vector3 coordinates.
TweenInfo Represents information about an in-between interpolation.
UDim Represents a universal dimension, which can dynamically be changed based on the width/height of the screen. Generally overshadowed by UDim2.
UDim2 Represents two universal dimensions; one for the X-axis of the user's screen, and one for the Y-axis. Used with GUI elements.
Vector2 Represents a two-dimensional coordinate system, on the X/Y axis.
Vector2int16 (UNUSED)
Vector3 Represents a three-dimensional coordinate system, on the X/Y/Z axis.
Vector3int16 Similar to Vector3, but the coordinates are integers constrained between -32,768 and 32,768, and there are no APIs for magnitude/unit measurement, dot/cross products, or lerping.

Functions[edit]

A few quick things to note:

  • Functions with a strike through their name are deprecated, and thus are no longer supported by Roblox. You can use these functions, but it's not recommended.
  • Functions that have italicized text cannot be used in normal Script icon.pngScripts and Localscript icon.pngLocalScripts

delay[edit]

void delay(number delayTime, function<void>() callBack)



Description:
Schedules a function to be called after delayTime seconds have elapsed.

Example:
delay(2,function ()
	print("This will print 2 seconds later.")
end)
 
wait(1)
print("This will print 1 second later.")

DebuggerManager[edit]

DebuggerManager DebuggerManager()

Description:
Returns the DebuggerManager.pngDebuggerManager class, which acts as an interface for Roblox's Lua debugger feature.

elapsedTime[edit]

number elapsedTime()

Description:
Returns how many seconds have elapsed since the program was started.

LoadLibrary[edit]

RbxLibrary LoadLibrary(string libraryName)

Description:
Returns a built-in Roblox library, based on the libraryName specified.

Example:
The following example iterates over the functions present in the ExplorerImageIndex27.pngRbxGui library, and prints the documentation of each function.

local RbxGui = LoadLibrary("RbxGui")
 
for _,funcName in pairs(RbxGui:GetApi()) do
	warn(funcName)
	print(RbxGui.Help(funcName))
end


Notes:

PluginManager[edit]

PluginManager PluginManager()

Description:
Returns the ExplorerImageIndex81.pngPluginManager, which can be used to make ExplorerImageIndex81.pngPlugin objects.

Notes:

  • This function is obsolete in plugins, as the plugin variable is now always declared in scripts that are running plugins.

printidentity[edit]

void printidentity()

Description:
Prints the identity level of the current thread to the output.

Example:
From a Script icon.pngScript:

printidentity()
Current identity is 2

From the command bar:

printidentity()
Current identity is 5

From a plugin:

printidentity()
Current identity is 6


See Also:

require[edit]

Variant require(Variant<ModuleScript, int> module)

Description:
Runs the supplied ExplorerImageIndex76.pngModuleScript 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.

Example:
--ModuleScript in the workspace
print("ModuleScript loaded for the first time")
return "Hello, world!"
print(require(game.Workspace.ModuleScript))
print(require(game.Workspace.ModuleScript))
print(require(52045834))
ModuleScript loaded for the first time
Hello, world!
Hello, world!
Underscore.lua

settings[edit]

GlobalSettings settings()

Description:
Returns the user's Configuration icon.pngGlobalSettings.

Notes:

  • Changes that are made to any of the settings will not be saved unless the user opens and closes the settings menu in Roblox Studio.

spawn[edit]

void spawn(function callback)



Description:
Schedules a function to be called in a separate thread in the next task scheduler step.

Example:
local count = 0
 
spawn(function ()
	while wait(1) do
		print("Loop #1")
		count = count + 1
	end
end)
 
while wait(1) do
		print("Loop #2")
		count = count + 1
		print("\tOverall loop count: " .. count)
end

stats[edit]

Stats stats()

Description:
Returns the InternalClass.pngStats service.

Notes:

tick[edit]

number tick()

Description:
Returns the number of seconds that have elapsed since the UNIX epoch (January 1st, 1970), on your computer.

Notes:

  • Unlike standard UNIX time, the value returned from this function also measures milliseconds.

time[edit]

number time()

Description:
Returns the number of seconds that have elapsed since the game started running.

Notes:

  • The game must be running, or else the value will be 0.

typeof[edit]

string typeof(Variant object)

Description:
Returns a string representing what kind of object was inputted.

UserSettings[edit]

UserSettings UserSettings()

Description:
Returns the client's Configuration icon.pngUserSettings.

Notes:

  • This function should only be used in a LocalScript.

version[edit]

string version()

Description:
Returns the string value representation of ROBLOX's version.

wait[edit]

Tuple<number> wait(number seconds)

Description:
Yields the current thread until the specified amount of seconds have elapsed.
If the seconds parameter is not specified, then it yields for a very short period of time (usually close to 1/30th of a second).
The function returns 2 values:

  • The actual time that was elapsed
  • The time that has elapsed since the program was started.

warn[edit]

void warn(Tuple<Variant> params)

Description:
Functions identically to print, except the output is styled as a warning, with yellow text and a timestamp.