@usbx/data Saving and leaderboards
local data = require ("@usbx/data" )data. profile_schemafunction # Declares the Profile every player gets. Declare it once; missing fields take their defaults, and players who joined before start loading then.
Use it for setting up, once, what every player saves, like their tokens, level and items.
schemaWhat every Profile holds.
optionsoptional Its version, and how to bring older Profiles up to it.
Build a profile_schema call version · migrate data. profilefunction waits # The player's Profile. Yields until it is loaded.
Use it for reading or changing a player's saved tokens when they buy something in your shop.
data. save_in_profilefunction # Keeps a per-player State in each player's Profile, so a value such as coins or a level lasts between visits. When a Profile loads, its saved value goes into the State, and every change of the State is written to the Profile, which saves as Profiles do.
data.save_in_profile<T>(state:
PlayerState <T>, path: string?) -> ()
Use it for keeping a player's tokens or level between visits, without writing any save code yourself.
stateA per-player State, from state.create_per_player.
pathoptional Where it goes in the Profile, such as "coins" or "stats.wins". The State's key by default.
Saved Documents of one schema, shared by every server of the game. Names have 1 to 100 characters, and names that start with __ are reserved.
Use it for saving things that players share, like guilds, clans or the buildings of a town, across every server.
collectionName of the collection.
schemaWhat every document holds.
optionsoptional Its version, and how to bring older documents up to it.
Build a documents call version · migrate The Key-Value Store with the name.
Use it for keeping game-wide settings, like a welcome message or a switch that turns an event on.
The Ordered Store of scores with the name. A leaderboard on the website shows one.
Use it for tracking wins or best times so you can show an all-time leaderboard.
data. profile_loadedevent # Fires when a player's Profile has loaded, with the player and the Profile.
example
data.profile_loaded :connect (function (player, profile) print (player.name, profile:get ("coins" )) end )Use it for giving a player their saved items the moment their data has loaded.
data. profile_failedevent # Fires when a player's Profile could not be loaded, with the reason.
Use it for telling a player their progress did not load, or logging the reason.