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

Memory and the Lua heap

These functions go under the API and work on the game's memory directly. They can do things nothing else here can, and they can also crash Roblox. Read this page before you use them.

All six need Scripts > Settings > Allow unsafe Luau turned on. While it is off, each one raises "<name> requires 'Allow unsafe Luau' (Scripts settings)" and does nothing.

Reading and writing memory

Function What it does
getbase() The address where RobloxPlayerBeta.exe is loaded
memory_read(type, address) Reads one value
memory_write(type, address, value) Writes one value

The type is one of these strings:

Type Size Reads as
"byte" 1 byte a whole number from 0 to 255
"int" 4 bytes a signed whole number
"float" 4 bytes a number
"double" 8 bytes a number
"uintptr_t" 8 bytes an unsigned whole number, for pointers
"string" up to 4096 bytes the printable text starting at the address

A safe first test is the start of the game's own file, which always begins with the letters "MZ":

Luau
local base = getbase()
print(string.format("base 0x%X", base))
print(memory_read("string", base)) -- MZ
print(memory_read("byte", base), memory_read("byte", base + 1)) -- 77 90

Reading

  • Reading an address that is not mapped returns 0 (or "" for a string) instead of raising.
  • A "string" read stops at the first byte that is not printable text, or after 4096 bytes.
  • Addresses are plain numbers, so base + 0x10 works as you would expect.

Writing

  • "int" takes a whole number from -2147483648 to 2147483647. For a bit pattern from 0x80000000 up, write value - 2^32.
  • "byte" takes 0 to 255 and "uintptr_t" takes 0 and up.
  • A fraction, an infinity or a number out of range raises an error before anything is written.
  • "string" writes the text and a zero byte after it, up to 4096 bytes.
  • A write that fails (for example to memory you cannot write) does nothing and raises nothing.

Big numbers

A Luau number is a double, which holds whole numbers exactly only up to 2^53 (9,007,199,254,740,992). Every address evasive gives you (getbase(), a getgc entry's addr) is below that and arrives exact.

A "uintptr_t" read of arbitrary memory can return something bigger. Past 2^53 the value is rounded, so value + 1 can equal value. If you read a pointer and do maths on it, check it first:

Luau
local function isExact(n)
    return n >= 0 and n < 2 ^ 53
end

Offsets change

Roblox updates often, and every update moves things around. An address you worked out from getbase() plus an offset is only right for the Roblox version you worked it out on. getrbxversion() tells you the version, so a script can refuse to run on one it does not know:

Luau
local KNOWN = "0.749.0.7491426"
if getrbxversion() ~= KNOWN then
    warn("this script was made for Roblox " .. KNOWN .. ", you have " .. getrbxversion())
    return
end

Searching the game's Lua heap

Games keep a lot of their data in Lua tables: weapon stats, cooldowns, speeds. These functions find table entries by their key name in the game's own Lua memory and change their values.

Function What it does
getgc(name) or getgc({ names }) Searches the heap and returns every entry with those keys
setgc(key, value) or setgc({ key = value }) Searches and sets in one go. Returns how many values changed.
applygc(cache, key, value) or applygc(cache, { key = value }) Sets values in entries you already found. Returns how many changed.

Each entry getgc returns is a table:

Field What it is
key The key name it was found under
value Its current value. For a table or function this is the raw address.
type "number", "boolean", "string", "table", "function" and so on
addr The address of the entry
table The address of the table that holds it

The same key usually turns up in many tables, so expect several entries per name.

Search once, apply often

A search reads the whole heap. It takes one to two and a half seconds, and your thread pauses while it runs (other scripts keep going). setgc searches on every call, so never call it in a loop.

applygc does not search. It works on a list getgc already returned and takes well under a millisecond for a few entries, so it is fine to call every frame. That is the pattern to use for values a game keeps resetting:

Luau
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local NAMES = { "FireRate", "Spread", "RecoilUp" }
local VALUES = { FireRate = 0.05, Spread = 0, RecoilUp = 0 }

local cache = {}

local function refresh()
    cache = getgc(NAMES)
    print("found", #cache, "entries")
end

refresh()

RunService.Heartbeat:Connect(function()
    applygc(cache, VALUES)
end)

-- the game builds new tables when you respawn: search again
Players.LocalPlayer.CharacterAdded:Connect(function()
    task.wait(2)
    refresh()
end)

The key names here are made up. Every game names its values differently. Run getgc with a guess, print the entries and look at what comes back before you write anything.

A cache can hold up to 4096 entries, which is the most one getgc returns. applygc refuses a longer list.

What gets written

evasive is careful about what it changes in the heap:

  • Only numbers and booleans are written, and only into an entry that already holds that type. A number never goes into a slot that holds a table, for example.
  • A string value is never written. Roblox runs several Lua states at once, and a string stored from outside could end up pointing into the wrong one and crash the game later. setgc and applygc skip those entries, leave them out of the count and say so on the console.
  • Right before each write, evasive reads the entry and its table again to make sure they are still what getgc found. An entry whose table was freed or rebuilt is skipped.

One gap is left that cannot be closed from outside: the game keeps running between that last check and the write. A table that changes in exactly that instant can still be written. In practice this is rare, but it is why a bad heap write can still crash the game.

To write a string into memory at an address you chose yourself, memory_write("string", address, text) still works.

Safety

  • Test on a server you do not care about. A crash takes your game client with it.
  • Read before you write. Print what getgc finds, check the types and values, and only then turn on the writes.
  • Values you change exist only in your client. The server keeps its own copy of anything that matters, and a game is free to check.
  • Turn Allow unsafe Luau off again when you are done with a script that needs it.