Greetings All, is anyone out there able to help me understand DataStores, I do understand and know that you could save Leaderstats, but I want/need to know how to save several things like checkpoints etc,..
Appreciated and Thank you!
Greetings All, is anyone out there able to help me understand DataStores, I do understand and know that you could save Leaderstats, but I want/need to know how to save several things like checkpoints etc,..
Appreciated and Thank you!
DataStoreService is a service, so you need to get it with game:GetService and put it in a variable
local DataStore = game:GetService("DataStoreService")
Then you need to get your data store. The data stores are tables that save some valors like
Table1 = {
Key1 = Value,
Key2 = Value
}
Table2 = {
Key1 = Value,
Key2 = Value
}
So you need to get your Table with GetDataStore in your data store service so:
local DataStore = game:GetService("DataStoreService")
local TableStored = DataStore:GetDataStore("Table1")
Table1 can be a string with a limit of 50 characters that represents the name of the table you can name it like MoneyData, LeaderstatsData or something.
So now you can use GetAsync, SetAsync, UpdateAsync, RemoveAsync to get and set data with the key name, I recommend that the key be the User Id of the player so you make sure that the key is not repeated for players
TableStored:GetAsync(KeyName) -- Returns the stored value
TableStored:SetAsync(KeyName, Value) --Set a value
TableStored:RemoveAsync(KeyName) --Delete the stored data
There is the basics functions
https://developer.roblox.com/en-us/api-reference/class/GlobalDataStore
Here is all the functions
So can I also save checkpoints with this?
You can answer your question, you can upload a value with your checkpoint number
DataStoreService is a service that saves/load data to Roblox's database and servers which you can utilize for an individual place.
To save multiple things, you must use a table that contains whatever values you want to save. I suggest to learn what tables are if you do not know how to use them.
When data is loaded, it will either return nil (no data), or error (this is why you use pcall), or the data itself.
Saving data may also cause errors so you use pcall for that as well.
Your question about saving multiple pieces of information to the Datastore has been answered countless times, here is one.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
https://developer.roblox.com/en-us/articles/Data-store