evasivedocs
Roblox scriptingLuau 0.748 · 24 guides · 385 API entries
API reference

Globals and libraries

The functions every script has, the console, waiting and threads, and the Lua base library.

Globals

Functions every script has, beside Luau's standard library.

27 entries

loadstring

functionWorks differently
loadstring(chunk [, chunkname]) -> function, string?

Compiles chunk into a function. Calling it runs the code and returns what its top level returns. On a syntax error you still get a function, which prints the error when called. The message comes back as the second value.

Note

Standard Luau returns nil and the message on a syntax error. Here the first value is a function either way, so test the second one.

Arguments
NameTypeDefaultDescription
chunkstringLuau source.
chunknameoptionalstring"loadstring"The name errors show.
Returns
  • function
  • string?
Example
Luau
local f, err = loadstring("return 1 + 1")
if err then warn(err) else print(f()) end

load

functionWorks differently
load(chunk [, chunkname]) -> function, string?

The same function as loadstring.

Note

See loadstring: a syntax error returns a function that prints it.

Arguments
NameTypeDescription
chunkstring
chunknameoptionalstring
Returns
  • function
  • string?
Example
Luau
local f = load("print('hi')")

WorldToScreen

function
WorldToScreen(position) -> Vector2, boolean

Projects a world position onto the Roblox window. Returns the point in client pixels (top left is 0, 0: the space of Drawing, mousemoveabs and Camera.ViewportSize) and whether it is visible. A point outside the window, or one the camera faces away from, comes back as (0, 0) and false.

Arguments
NameTypeDescription
positionVector3
Returns
  • Vector2 pointClient pixels.
  • boolean onScreen
Example
Luau
local pos, visible = WorldToScreen(part.Position)
if visible then
    print(pos.X, pos.Y)
end

notify

function
notify(message [, title] [, duration])

Shows a notification at the right edge of the Roblox window for duration seconds (0.1 to 120). At most six show at once, and a seventh pushes out the oldest.

Arguments
NameTypeDefaultDescription
messagestring
titleoptionalstring""
durationoptionalnumber5
Example
Luau
notify("Loaded", "My script", 3)

identifyexecutor

function
identifyexecutor() -> string, string

The runtime's name and version: "evasive" and "1.0.0".

Returns
  • string
  • string
Example
Luau
local name, version = identifyexecutor()

getgamename

function
getgamename() -> string

The name of the experience you are in, as the Roblox website lists it. Fetched once per game, then cached. Returns "" when no game is loaded. Yields while it fetches.

Returns
  • string
Example
Luau
print(getgamename())

getscripts

function
getscripts() -> { Instance }

Every LocalScript, ModuleScript and Script in the game. It can be a long list, and the call yields while it walks the tree.

Returns
  • { Instance }
Example
Luau
print(#getscripts())

base64encode

function
base64encode(data) -> string

Encodes data as standard Base64. Every byte is encoded, NUL bytes included.

Arguments
NameTypeDescription
datastring
Returns
  • string
Example
Luau
local b = base64encode("hello")

base64decode

function
base64decode(data) -> string

Decodes Base64 back to the original bytes. Raises on text that is not Base64. An empty string gives "".

Arguments
NameTypeDescription
datastring
Returns
  • string
Example
Luau
print(base64decode("aGVsbG8="))

getping

function
getping() -> number

Your ping to the game server in milliseconds, from Roblox's own network stats. 0 while no place is loaded.

Returns
  • number
Example
Luau
print(getping())

tick

functionWorks differently
tick() -> number

Seconds from a steady clock, for timing. Subtract two readings to get the time between them. It does not tell the date. Use os.time for that.

Note

Roblox's tick() is Unix time. This one counts from an arbitrary start, so only differences mean anything.

Returns
  • number
Example
Luau
local t0 = tick()
-- work
print(tick() - t0)

typeof

function
typeof(value) -> string

Like type, but names Roblox types: Vector3, CFrame, Color3, Instance, Drawing, EnumItem, RBXScriptSignal and so on, where type says userdata.

Arguments
NameTypeDescription
valueany
Returns
  • string
Example
Luau
print(typeof(Vector3.new()))

getfenv

function
getfenv([target]) -> table

The environment of a function, or of a call level. With no argument, 0 or 1 you get the script's own environment, every global included. _G is a separate table that every running script shares.

Arguments
NameTypeDescription
targetoptional(function | number)
Returns
  • table
Example
Luau
getfenv().myValue = 1

setfenv

function
setfenv(target, env) -> function

Sets the environment of a function (or of a call level): its global names are then looked up in env. Returns the function.

Arguments
NameTypeDescription
targetfunction | number
envtable
Returns
  • function
Example
Luau
setfenv(f, { print = print })

getrbxversion

function
getrbxversion() -> string

The running Roblox client's version, as its log files name it (e.g. "0.749.0.7491426").

Returns
  • string
Example
Luau
print(getrbxversion())

gethwid

function
gethwid() -> string

An identifier of this PC. It is the same on every call.

Returns
  • string
Example
Luau
local id = gethwid()

queue_on_teleport

function
queue_on_teleport(source)

Queues source to run after your next teleport to another server or place. It is compiled now, so a syntax error raises here. It runs as a thread of the script that queued it, with that script's globals. That script keeps running until then.

Arguments
NameTypeDescription
sourcestring
Example
Luau
queue_on_teleport([[print("arrived")]])

queueonteleport

function
queueonteleport(source)

The same function as queue_on_teleport.

Arguments
NameTypeDescription
sourcestring
Example
Luau
queueonteleport([[print("arrived")]])

getaimtarget

function
getaimtarget() -> Instance?

The character evasive's aim is locked on to right now, or nil when it has none or the aim is off. A player comes back as its Character model.

Returns
  • Instance?
Example
Luau
local t = getaimtarget()
if t then print(t:GetFullName()) end

gettriggertarget

function
gettriggertarget() -> Instance?

The character under evasive's trigger at this moment, or nil.

Returns
  • Instance?
Example
Luau
local t = gettriggertarget()

cancallserver

function
cancallserver() -> boolean

Always false: evasive works from outside the game. The functions that need code inside the client are not available.

Returns
  • boolean
Example
Luau
if not cancallserver() then print("external") end

decompile

functionNot available
decompile(script) -> string

Would return a script's source. Prints why it cannot and returns "".

Warning

A script's bytecode cannot be read: evasive reads Roblox memory from outside, and the bytecode it would need is compressed and protected. The call prints this and returns an empty string.

Arguments
NameTypeDescription
scriptInstance
Returns
  • string

getscripthash

functionNot available
getscripthash(script) -> string

Would hash a script's bytecode.

Warning

A script's bytecode cannot be read: evasive reads Roblox memory from outside, and the bytecode it would need is compressed and protected. The call raises.

Arguments
NameTypeDescription
scriptInstance
Returns
  • string

getscriptbytecode

functionNot available
getscriptbytecode(script) -> string

Would return a script's compiled bytecode.

Warning

A script's bytecode cannot be read: evasive reads Roblox memory from outside, and the bytecode it would need is compressed and protected. The call raises.

Arguments
NameTypeDescription
scriptInstance
Returns
  • string

firetouchinterest

functionNot available
firetouchinterest(part, target, state)

Would fire a touch (state 0) or untouch (1) between two parts.

Warning

Needs code running inside the Roblox client. evasive reads and writes the game's memory from outside, so this call checks its arguments and then raises. cancallserver() is always false.

Arguments
NameTypeDescription
partBasePart
targetBasePart
statenumber

fireclickdetector

functionNot available
fireclickdetector(detector [, distance] [, event])

Would fire a ClickDetector (MouseClick, RightMouseClick, MouseHoverEnter or MouseHoverLeave).

Warning

Needs code running inside the Roblox client. evasive reads and writes the game's memory from outside, so this call checks its arguments and then raises. cancallserver() is always false.

Arguments
NameTypeDescription
detectorInstance
distanceoptionalnumber
eventoptionalstring

fireproximityprompt

functionNot available
fireproximityprompt(prompt)

Would trigger a ProximityPrompt at once.

Warning

Needs code running inside the Roblox client. evasive reads and writes the game's memory from outside, so this call checks its arguments and then raises. cancallserver() is always false.

Arguments
NameTypeDescription
promptInstance

Console

Output to Scripts > Console, and to the Output card or its pop-out window.

3 entries

print

function
print(...)

Writes its arguments to the console, separated by spaces.

Arguments
NameTypeDescription
...any
Example
Luau
print("health", 100)

warn

function
warn(...)

Writes a yellow warning line.

Arguments
NameTypeDescription
...any
Example
Luau
warn("low health")

error

functionWorks differently
error(...)

Writes a red error line and returns. The script keeps running. To raise an error that pcall catches, use assert(false, message).

Note

Standard Luau's error raises. Here it only prints.

Arguments
NameTypeDescription
...any
Example
Luau
error("not in a game")

Scheduler & modules

Yielding, threads and modules. Scripts run on their own thread, which steps 240 times a second. A script that runs 3 seconds without yielding is stopped.

5 entries

wait

function
wait([seconds]) -> number

Yields the current thread for seconds (by default until the next tick) and returns the time that passed.

Arguments
NameTypeDescription
secondsoptionalnumber
Returns
  • number
Example
Luau
while wait(0.5) do
    print("tick")
end

spawn

function
spawn(fn, ...) -> thread

Runs fn on a new thread at once, with the extra arguments. The caller continues when it yields or ends.

Arguments
NameTypeDescription
fnfunction
...any
Returns
  • thread
Example
Luau
spawn(function() wait(1) print("later") end)

require

function
require(path) -> any

Runs a module and returns what it returns, once per script (later calls get the same value). path is a .lua or .luau file relative to the scripts folder, not the readfile workspace, and it cannot leave that folder. A path without an extension, another extension or a missing file raises an error that names the path.

Arguments
NameTypeDescription
pathstring
Returns
  • any
Example
Luau
local util = require("lib/util.luau")

setfastflag

functionNot available
setfastflag(flag, value)

Checks that both arguments are strings and does nothing else.

Warning

evasive leaves the client's fast flags alone. The function is there so scripts that call it keep loading.

Arguments
NameTypeDescription
flagstring
valuestring

getfastflag

functionNot available
getfastflag(flag) -> number

Returns 0 for every flag.

Warning

evasive does not read the client's fast flags. The stub returns 0 so scripts that call it keep loading.

Arguments
NameTypeDescription
flagstring
Returns
  • number

task

Roblox's task library.

5 entries

task.spawn

function
task.spawn(fn, ...) -> thread

Runs fn on a new thread now, passing the extra arguments, and returns the thread. The caller continues when fn yields or ends.

Arguments
NameTypeDescription
fnfunction
...any
Returns
  • thread
Example
Luau
task.spawn(print, "hi")

task.defer

function
task.defer(fn, ...) -> thread

Runs fn on a new thread later in the same scheduler cycle, after the work already queued.

Arguments
NameTypeDescription
fnfunction
...any
Returns
  • thread
Example
Luau
task.defer(function() print("after") end)

task.delay

function
task.delay(seconds, fn, ...) -> thread

Runs fn on a new thread after seconds.

Arguments
NameTypeDescription
secondsnumber
fnfunction
...any
Returns
  • thread
Example
Luau
task.delay(2, print, "two seconds later")

task.wait

function
task.wait([seconds]) -> number

Yields for seconds (by default until the next tick) and returns the time that passed.

Arguments
NameTypeDescription
secondsoptionalnumber
Returns
  • number
Example
Luau
local dt = task.wait()

task.cancel

function
task.cancel(thread)

Cancels a thread: one that is waiting or not started yet never runs again.

Arguments
NameTypeDescription
threadthread
Example
Luau
local t = task.delay(5, print, "never")
task.cancel(t)

Lua base library

Luau 0.748's standard globals. The string, table, math, bit32, buffer, coroutine and utf8 libraries work as Luau documents them. os has clock, time, date and difftime, and debug has info and traceback. This list covers the base functions.

19 entries

type

function
type(value) -> string

The Luau type. Roblox datatypes and instances are "userdata". Use typeof for their names.

Arguments
NameTypeDescription
valueany
Returns
  • string
Example
Luau
print(type(Vector3.new()))

tostring

functionWorks differently
tostring(value) -> string

Converts a value to text, honouring __tostring.

Note

Roblox datatypes print with their type name and four decimals: tostring(Vector3.new(1, 2, 3)) is "Vector3(1.0000, 2.0000, 3.0000)", where Roblox prints "1, 2, 3".

Arguments
NameTypeDescription
valueany
Returns
  • string
Example
Luau
print(tostring(Vector3.new(1, 2, 3)))

tonumber

function
tonumber(value [, base]) -> number?

Parses a number (spaces trimmed, 0x hex accepted, base 2 to 36), or nil.

Arguments
NameTypeDescription
valueany
baseoptionalnumber
Returns
  • number?
Example
Luau
print(tonumber("ff", 16))

pairs

function
pairs(t) -> function, table, any

Iterates every key of a table (the raw table: __iter is not used).

Arguments
NameTypeDescription
ttable
Returns
  • function
  • table
  • any
Example
Luau
for k, v in pairs(t) do end

ipairs

function
ipairs(t) -> function, table, number

Iterates t[1], t[2], ... up to the first nil.

Arguments
NameTypeDescription
ttable
Returns
  • function
  • table
  • number
Example
Luau
for i, v in ipairs(list) do end

next

function
next(t [, key]) -> any, any

The key after key in a table, and its value.

Arguments
NameTypeDescription
ttable
keyoptionalany
Returns
  • any
  • any

select

function
select(n, ...) -> ...any

The arguments from the nth on. A negative n counts from the end, and "#" gives the count.

Arguments
NameTypeDescription
nnumber | string
...any
Returns
  • ...any
Example
Luau
print(select("#", 1, 2, 3))

unpack

function
unpack(t [, i] [, j]) -> ...any

t[i] to t[j] (by default 1 to #t). The same as table.unpack.

Arguments
NameTypeDescription
ttable
ioptionalnumber
joptionalnumber
Returns
  • ...any
Example
Luau
print(unpack({ 1, 2, 3 }))

assert

function
assert(value, ... [, message]) -> ...any

Raises an error pcall can catch when value is false or nil, with message or "assertion failed!". Otherwise it returns all its arguments. Use it to raise errors, since error() only prints.

Arguments
NameTypeDescription
valueany
messageoptionalstring
...any
Returns
  • ...any
Example
Luau
assert(player, "no player")

pcall

function
pcall(f, ...) -> boolean, ...any

Calls f in protected mode: true and its results, or false and the error message with the script name and line.

Arguments
NameTypeDescription
ffunction
...any
Returns
  • boolean
  • ...any
Example
Luau
local ok, err = pcall(function() return nil + 1 end)

xpcall

function
xpcall(f, handler, ...) -> boolean, ...any

Like pcall, with handler called on the error message. The extra arguments go to f.

Arguments
NameTypeDescription
ffunction
handlerfunction
...any
Returns
  • boolean
  • ...any
Example
Luau
xpcall(f, warn, 1, 2)

setmetatable

function
setmetatable(t [, mt]) -> table

Sets t's metatable and returns t. A metatable with __metatable is protected and cannot be changed.

Arguments
NameTypeDescription
ttable
mtoptionaltable
Returns
  • table

getmetatable

function
getmetatable(value) -> any

The metatable, or its __metatable field when it has one.

Arguments
NameTypeDescription
valueany
Returns
  • any

newproxy

function
newproxy([withMetatable]) -> userdata

A blank userdata. With true it gets its own metatable (getmetatable returns it) so metamethods work.

Arguments
NameTypeDescription
withMetatableoptionalboolean
Returns
  • userdata
Example
Luau
local p = newproxy(true)

rawget

function
rawget(t, key) -> any

Reads t[key] without metamethods.

Arguments
NameTypeDescription
ttable
keyany
Returns
  • any

rawset

function
rawset(t, key, value) -> table

Writes t[key] without metamethods and returns t.

Arguments
NameTypeDescription
ttable
keyany
valueany
Returns
  • table

rawequal

function
rawequal(a, b) -> boolean

Compares without __eq.

Arguments
NameTypeDescription
aany
bany
Returns
  • boolean

rawlen

function
rawlen(value) -> number

The length without __len.

Arguments
NameTypeDescription
valuetable | string
Returns
  • number

gcinfo

function
gcinfo() -> number

The Luau VM's memory use in kilobytes. Every script runs in the same VM.

Returns
  • number
Example
Luau
print(gcinfo())