Data Persistence

From Legacy Roblox Wiki
Revision as of 17:51, 5 June 2011 by >Sncplay42 (added back "per player per place")
Jump to navigationJump to search

Data Persistence is a method of saving data for games so that the data can then be loaded when the player visits the game again.

How it works

Before data can be loaded or saved, the script should make sure the data is loaded. This is done by waiting until the DataReady property of the player is true, which can be done using the WaitForDataReady function.

When the data is ready, scripts can use the functions SaveBoolean, SaveString, SaveNumber and SaveInstance to store data ready for saving. When the player leaves the game, the data is sent to the website.

When the player visits again, their data will be loaded, ready for the script to get the values back using the LoadBoolean, LoadString, LoadNumber and LoadInstance functions.

Example

To save data:

game.Players["Player"]:SaveString("Message", "Hello world!")

To load data:

print(game.Players["Player"]:LoadString("Message"))
>Hello world!


Restrictions

The only major restriction with using the Data Persistence features is that none of the functions can be called from a LocalScript. Another small restriction is that there is a reasonable limit on how much data can be stored per player per place - see DataComplexity for details.

See Also

Tutorials

Methods