> Agent-readable docs index: /llms.txt. Download /docs.zip to grep all markdown files locally.

---
title: Database
icon: database
---

# <ApiPageIcon icon="database" />Database

<Heading level={2} id="database-1">
  database

  <ApiTag label="global table" />
</Heading>

A key and value store that is saved to disk. The data stays after the game restarts.

Use `database` like a table. `database[key] = value` saves the value, and `database[key]`
returns the saved value. If the key was never set, it returns **nil**. Assign **nil** to a key
to remove it.

Keys must be strings. Any other key type throws an error. You can save numbers,
strings, booleans, and tables of these values. Functions,
userdata, and cdata are saved as **nil**. Tables that are nested more than 16 levels deep are
also saved as **nil**.

Each script has its own keys. A function of your script reads and writes the keys of your
script, even when another script calls it. In a library, `database` uses the keys of the
script that runs the library's code.

When a script is removed in the menu, its keys are removed too. When a developer script is
renamed in the menu, its keys are kept. If you delete or rename the folder of a script outside
the menu, its keys are not removed.

A key can be at most 1 KB long. A value can be at most 4 MB after it is encoded. The keys and
values of one script together can be at most 16 MB, and one script can have at most 65536
keys.

An assignment that goes over a limit throws an error, and the saved value does not change.
An assignment that makes the total size smaller always works, and assigning **nil** always
works.

<ApiMembers>
  <ApiMember kind="prop" name="database[string]" ret="[[{&#x22;s&#x22;:&#x22;any&#x22;,&#x22;k&#x22;:&#x22;prim&#x22;}]]" />
</ApiMembers>
