Script environment
All custom global variables available in the script environment.
Global variables
const Instance
script
const Instance
scriptA constant reference to the script.
The constant script
variable is always evaluated to nil
in other environments besides the local and server script environments. In scripts that have been instantiated through the means of using NewScript
or NewLocalScript
, script
will always be a reference to the script instance that has been generated by the functions.
const string
_VERSION
const string
_VERSIONA constant reference to the version of the interpreter and compiler.
print(_VERSION) -- output: Luau
const Player
owner
const Player
ownerA constant reference to the player who owns the script.
-- the owner of this script is Players.RazvanJTL
print(owner.Name) -- output: RazvanJTL
print(owner.Character) -- output: player's character
Global functions
const function require(module: number | ModuleScript, silenced: boolean?): any
const function require(module: number | ModuleScript, silenced: boolean?): any
The constant require
function that functions just like in vanilla Luau. However, it has been modified to serve restrictions on its usage and to be able to prevent the call stack from being printed to the developer console.
-- attempting to require a MainModule (asset ID) without
-- meeting the 112x4 privilege level requirement will result in a error
require(1, true)(owner and owner.Name) -- error: attempted to use restricted global (require)
-- require can also load ModuleScripts that have been instantiated through
-- the means of using NewModuleScript
local get_contents = require(NewModuleScript([[
return function()
return "hi"
end)
]])) -- returns: () -> string
print(get_contents()) -- output: hi
const function NewScript(source: string, parent: Instance?): Script
const function NewScript(source: string, parent: Instance?): Script
Constant function that instantiates a server script which has the purpose of running the specified code. The parent argument defaults to ServerScriptService
if no parent has been specified.
Aliases: NS
, ns
, new_script
Note that NewScript
cannot be used within another server script which has been instantiated by NewScript
.
NewScript([[
print("hi,", owner.Name)
]]) -- output: hi, RazvanJTL
const function NewLocalScript(source: string, parent: Instance?): LocalScript
const function NewLocalScript(source: string, parent: Instance?): LocalScript
Constant function that instantiates a local script which has the purpose of running the specified code. The parent argument defaults to the script's owner if no parent has been specified.
Aliases: NLS
, nls
, new_local_script
Note that NewLocalScript
cannot be used within another server or local script which has been instantiated by either NewScript
or NewLocalScript
.
local Players = game:GetService("Players")
NewLocalScript([[
print(owner.Name)
]], Players.SomeoneYouDontKnow) -- output on client-side: RazvanJTL
const function NewModuleScript(source: string): () -> any
const function NewModuleScript(source: string): () -> any
Constant function that instantiates a module script.
Aliases: NMS
, nms
, new_module_script
local module = NewModuleScript([[
return {
do_something = function()
-- does something
return nil
end
}
]]) -- returns: executable -> {do_something: () -> any}
print(module().do_something()) -- output: nil
print(require(module).do_something()) -- output: nil
const @deprecated function LoadLibrary(library: "RbxGui" | "RbxStamper" | "RbxUtility"): any
const @deprecated function LoadLibrary(library: "RbxGui" | "RbxStamper" | "RbxUtility"): any
Constant function that executes and returns the contents of the specified library.
Aliases: loadLibrary
, load_library
This is a removed and deprecated Roblox function and should not be used in new work. This function has only been added to maintain compatibility.
const function print(...: any)
const function print(...: any)
Prints all specified arguments to the console.
const function warn(...: any)
const function warn(...: any)
Acts the same as print
, with the only difference being that the color of the output will be yellow.
const function error(exception: string, level: number)
const function error(exception: string, level: number)
Outputs an error to the console and halts the execution of the script if the error isnt caused in protected mode. If no level of information that will be outputted has been explicitly specified, it will default to 1
.
Last updated