Luduvo Contents
Theme
On this page

CloudStore

a store every server of the experience shares, read and written asynchronously

Methods

5 members

fetch(key: number | string, callback: (any, number, string?) -> ()): ()

load the record under key, invoking callback with data, version, and error

Parameters
NameTypeDescription
keynumber | stringKey identifying the record to fetch.
callback(any, number, string?) -> ()Receives the stored value, the committed version number, and an optional error string on failure.
keys(after: string?, limit: number?, callback: ({string}, string?) -> ()): ()

list stored keys starting after cursor with optional limit

Parameters
NameTypeDescription
afterstring?Lists the keys ordered after this one.
limitnumber?Maximum keys per page.
callback({string}, string?) -> ()Receives the array of keys and an optional cursor string for the next batch.
put(key: number | string, value: {[string]: any}, expect_version: number?, callback: ((number?, string?) -> ())?): ()

store value under key with optional expected version check

Parameters
NameTypeDescription
keynumber | stringKey identifying the record to store.
value{[string]: any}Table of fields to persist in the record.
expect_versionnumber?Version the record must still have; nil overwrites unconditionally.
callback((number?, string?) -> ())?Receives the committed version number, or nil and an error string on failure.
remove(key: number | string, callback: ((boolean, string?) -> ())?): ()

delete the record under key

Parameters
NameTypeDescription
keynumber | stringKey identifying the record to remove.
callback((boolean, string?) -> ())?Receives whether the record was removed, and an optional error string on failure.
update(key: number | string, transform: (any, number) -> any, callback: ((number?, string?) -> ())?): ()

read and update the record via a transform function

Parameters
NameTypeDescription
keynumber | stringKey identifying the record to update.
transform(any, number) -> anyReceives the current value and version and returns the value to store.
callback((number?, string?) -> ())?Receives the committed version number, or nil and an error string on failure.

Loading Persistent Data Across Servers

Lifecycle: Server

Cloud reads are asynchronous, so the record and its version arrive in a callback.

Luau
local cloud = game.CloudStore.open("PlayerData")local function loadPlayerData(userId: number)	cloud:fetch(userId, function(data, version, err)		if err ~= nil then			warn(string.format("Load failed for user %d: %s", userId, err))			return		end		local profile = data or { gold = 0, inventory = {} }		print(string.format("Loaded profile for %d (v%d)", userId, version))	end)end