Skip to content

Store

System · Store · server and client scripts

Store saves values by key so they survive a server restart. Every place with the same owner shares a store by name: two places of one creator that open "profiles" read and write the same data. Use CloudStore when servers that run at the same time need to see each other's changes or resolve conflicts.

On a published place, Open loads the whole store from the backend, Get reads from memory, and Set and Remove change memory at once and save to the backend in the background, in order. Every handle method (Get, Set, and Remove) returns a StoreStatus first.

When you run a place in Studio or locally, store files are in the project's stores directory; otherwise in LDV_STORE_DIR, stores next to the place file, or stores in the working directory, in that order. There each Set writes to the file before it returns.

Open

FunctionServer only
Open(name: string) -> Store

Open opens or creates the store name and returns its Store handle. Opening the same name again returns the same store.

Parameter Type Description
name string 1 to 31 letters, digits, '_', or '-'.

Example

-- Server script: count how many times this server has started.
local stats = Store.Open("server_stats")
local status, data = stats:Get("1")
local count = if status == "Ok" and type(data) == "table" then (data :: { starts: number }).starts else 0
stats:Set("1", { starts = count + 1 })
print("starts: " .. tostring(count + 1))
Errors (3)
Error When
Store.Open: '<name>' is not a store name; use 1 to 31 letters, digits, '_' or '-' The store name has invalid characters or length.
Store.Open: this place has 8 stores open, the most it can hold; reuse an open store A place can have 8 stores open; keep the handle in a variable.
Open can only be called from the server Called from a client script.