Hello DevFourm! I have been working on a game where you can click food to earn money. With this money, you can buy upgrades to get you more money with every click.
Anyways, I want to make a Data Store system to save the player’s data when they leave. I have never really understood how DataStores worked so I need some help.
So DataStores can store either a value or a table to a specific “key”, which we usually use the PlayerID. To make one save an IntValue, it would be “save”(value, key) and to get that value back we can just do “get”(key).
To start with a datastore, you have to create one using :GetDataStore()
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("ThisIsADataStore") --The name does not matter, as long as it is unique.
-- For our "get" command it is called :GetAsync() and the parameters are the same.
local data = DataStore:GetAsync(Player.UserId)
-- And finally for our "save" command, it is called "SetAsync" and the parameters are once again the same
DataStore:SetAsync(IntValue.Value, Player.UserId)
Obviously this is not a functioning script as is, but it should hopefully explain the concepts… To put this into practice, you would use GetAsync() as the player joins to see if they have any data saved and SetAsync() as the player leaves to save their data.