Skip to content
Untitled Sandbox - Developer Documentation
docs/types/KeyValueStore

KeyValueStore

A place to save small values under names you choose, which you get from data.store.

Fields

namestring

KeyValueStore:get

method

Gives back the value that is saved in the store for a key.

KeyValueStore:get(key: string) -> any
example
local motd = settings:get("motd")

Use it forloading the welcome message that each server shows when it starts.

keyThe key.

KeyValueStore:set

method

Saves a value for a key, and saving nil removes the key.

KeyValueStore:set(key: string, value: any) -> ()
example
settings:set("motd", "Welcome!")

Use it forchanging the welcome message that every server of your game reads.

keyThe key.
valueThe new value, at most 64 KB as JSON. Nil removes the key.

KeyValueStore:update

method

Gives a key's value to a function you write, and saves whatever it returns.

KeyValueStore:update(key: string, transform: (any) -> any) -> any
example
settings:update("visits", function(value) return (value or 0) + 1 end)

Use it forcounting total visits safely while many servers add to the same number at once.

keyThe key.
transformGets the value and returns the new one, not nil. It can run more than once, and must not yield.

KeyValueStore:remove

method

Deletes the saved value for a key from the store.

KeyValueStore:remove(key: string) -> ()
example
settings:remove("motd")

Use it forclearing an event message once the event is over, so players stop seeing it.

keyThe key.
↑ ↓ moveEnter openEsc close