James
Active Coder
NOTE: THIS TUTORIAL IS FOR ROBLOX LUA ONLY, NOT ANY OTHER TYPE OF LUA.
What is datastore?
datastore is a Roblox service used for saving data, in my opinion, it is very easy but I know some people have some trouble with it.
This tutorial is going to go over the very basics.
How do I use datastore?
[CODE title="One" highlight="1"]local dataStoreService = game:GetService("DataStoreService")[/CODE]
This code gets the datastore service
With this service, you can do the data saving.
How do I save?
So, to save you need to call the function SetAsync
SetAsync takes 2 arguments, Key and Data
The Key value is the key associated with the data you are saving, this is useful for getting that data after it has been saved.
The data value is what you are saving, this can be anything from a number to a dictionary
Okay, now how do I get that saved data?
To get data you have saved is very easy
You use a function called GetAsync
GetAsync takes one variable, the Key
The Key is what you saved the data with
In the event that no data is saved to the key, you give the function returns a nil value
You can validate data by doing
This makes it so that it either gets the key to that data or returns 5
Alright, that is it for basic datastore, if you want to see how to put this into action and make a leaderstats saving system then like this post and I will do one!
Message me at JamesWa#2406 on discord if you need help.
What is datastore?
datastore is a Roblox service used for saving data, in my opinion, it is very easy but I know some people have some trouble with it.
This tutorial is going to go over the very basics.
How do I use datastore?
[CODE title="One" highlight="1"]local dataStoreService = game:GetService("DataStoreService")[/CODE]
This code gets the datastore service
With this service, you can do the data saving.
How do I save?
So, to save you need to call the function SetAsync
SetAsync takes 2 arguments, Key and Data
The Key value is the key associated with the data you are saving, this is useful for getting that data after it has been saved.
The data value is what you are saving, this can be anything from a number to a dictionary
Code:
local dataStoreService = game:GetService("DataStoreService")
dataStoreService:SetAsync("ThisIsTheKey","ThisIsTheData")
dataStoreService:SetAsync("ThisIsAnotherKey,5)
Okay, now how do I get that saved data?
To get data you have saved is very easy
You use a function called GetAsync
GetAsync takes one variable, the Key
The Key is what you saved the data with
Code:
local dataStoreService = game:GetService("DataStoreService")
local Data = dataStoreService:GetAsync("ThisIsTheKey")
In the event that no data is saved to the key, you give the function returns a nil value
You can validate data by doing
local Data = dataStoreService:GetAsync("ThisIsTheKey") or 5
This makes it so that it either gets the key to that data or returns 5
Alright, that is it for basic datastore, if you want to see how to put this into action and make a leaderstats saving system then like this post and I will do one!
Message me at JamesWa#2406 on discord if you need help.