Skip to content

Data Stores ​

Single player games save progress on the player's machine. Gamma does this through Roblox's DataStores API, so code written for Roblox data stores, and libraries built on them, work without changes.

luau
local progress = DataStores:GetDataStore("Progress")

progress:SetAsync("Level", 3)
progress:UpdateAsync("Coins", function(coins)
	return (coins or 0) + 10
end)
print(progress:GetAsync("Level"), progress:GetAsync("Coins"))

API ​

  • DataStores:GetDataStore(name, scope) returns the DataStore for a name and an optional scope ("global" by default). The same name and scope always give the same store.
  • GetAsync(key) returns the value, or nil when the key is not set.
  • SetAsync(key, value) stores a value. Storing nil removes the key.
  • UpdateAsync(key, transform) calls transform with the current value and stores what it returns. Returning nil leaves the key unchanged, and UpdateAsync then returns nil. The transform cannot yield.
  • IncrementAsync(key, delta) adds delta (1 by default) to a number, or to 0 when the key is not set, and returns the result.
  • RemoveAsync(key) removes the key and returns the value it had.

Names, scopes and keys must be 1 to 50 characters. A value can be nil, a boolean, a finite number, a string, or a table of those; anything else is an error. Tables are stored as copies, so changing a table after storing it does not change what is saved.

Differences from Roblox ​

  • The data lives on the player's machine and is not shared between players.
  • The Async methods return at once instead of yielding, because there is no request to wait for. Code that expects them to yield still works.
  • There are no request limits or retries, and none of the version, metadata, ListKeysAsync, OrderedDataStore or GetGlobalDataStore APIs yet.

Where data is saved ​

The engine host decides where data goes. With a save directory, each store is one JSON file in it, named after the store and its scope, written after every change. Without one, stores live in memory and are gone when the game closes. Gamma run keeps stores in memory, so tests always start from empty stores. Gamma play saves to a folder for the game in the user's data folder, named after the project folder or place file: ~/.local/share/Gamma/<Game>/ on Linux, %APPDATA%\Gamma\<Game>\ on Windows and ~/Library/Application Support/Gamma/<Game>/ on macOS (SDL's SDL_GetPrefPath). Two games with the same folder name share it. Exported games will set their own. A file that cannot be read makes GetDataStore fail rather than replace the file with an empty store.

Apache License 2.0