Have you ever in the situation where you want to save data but it loads again every time you enter the game again? Ever since Data Persistence has become useless, Roblox introduces data stores that are much more functioning. Then, how to work with data stores on Roblox?
Working wit data stores on Roblox has something to do with enabling API access. How to enable API access? Before jumping on the method to enable API access, it is better for you to read the thing from the start.
There are three methods to work with data stores on Roblox. The first one is setting the data store. The first thing that you have to do to set the data store is to configure API. This one does not involve any bit of scripting, but in order to activate all of the data store API, you must first enable the API access. In order to enable the API access, you need to go to the Develop tab and click on “Games”. This one should take you to all of the current game places you own. You need to find your game and click on the gear.
By doing that step, there should appear a dropdown menu, and simply press “Configure”. After that, check the box enabled “Enable Studio Access to API Services” and save. Now, you should have access to the complete API. The next thing that you have to do is to retrieve the data store. You have to use the data store API to call for the data store, as you will need to reference it. To start, please open the script on Roblox, and name the variable that you would like to use to call for the reference. After that, use the variable as needed. You have successfully called the data store wit the variable “datastore”. Bow, every time you need to retrieve the data store, you are able to simply name it by its variable. Please take a note that if the data store has not been created yet, it will automatically create the new one.
The second method is using data store methods. First, use GetAsync. You can use GetAsync to return the value of the entry in the data store with the given key. Please make sure to give every player the unique set of keys, as setting two players the same key will override their own in game data that can cause chaos between the two parties. Second, SetAsync. You can use it to set the value of the key, and overrides all existing data stored for the unique key. Third, use UpdateAsync to return the value of the key and update it with the new value. Fourth, use IncrementAsync to increment the value for the key and return the incremented value.
The third method is data store events and updating data. To use this method, you need to set a unique key. Then, update the data. In the end, you everything will be stored and the data of the player will be updated.