I know this is not a request site, but I'm not asking for a free script, I'm asking for a teacher. The wiki is very, very confusing, and I want to know how to use data store. I would greatly appreciate an answer that explains how to accomplish what was explained in the title (assume the BoolValue is in the player). Please use language that I can understand, not crazy, confusing, big words from computer science.
I know some people might say something like, "u idiot, try it yourself before asking, nob!" and I would try it myself, if the wiki taught it more clearly. But while the wiki is good for some things, when I looked up DataStore it was very confusing, and I did not understand it.
Thanks!
NOTE: Currently, I only know about Setting and Retrieving data. Therefore, I don't know everything about Data Stores. Sorry for the inconvenience.
Accessing Data Stores
We use "DataStoreService"
to access Data Stores. for example:
DSS = game:GetService("DataStoreService")
DATA STORES MUST ONLY BE USED IN SERVER SCRIPTS. What Are Data Stores? Imagine a drawer, as a player. The Drawer would have a lot of files. Thise Files would be called the Data Stores. In those files, are 2 columns. A Key and a Value. You use a Key to gain/set data. There is a limit, please read the wiki for more info.
Getting Data Stores
First, you have to get the data store, before you can do anything else. We use :GetDataStore(name)
to do that.
If the Data Store hasn't been created yet, ROBLOX will automatically create a new one.
Getting Values
In this case, we use :GetAsync(key)
. This gives us the value of the key in the parenthesis. Example:
print(DSS:GetDataStore(player.Name.."'s Random"):GetAsync(Random))
--Output will print whatever the values are for that key.
If there is no key/value, it will return nil
Setting Values
In order to get values, you need to set one. To set a NEW value, you would use :SetAsync(key,value)
.
Example:
DSS:GetDataStore(player.Name.."'s Random"):SetAsync("LOL", true) -- Creates a new row in the 2 columns and sets the value to true.
Example Script This script will save the player's Cash if it has not been saved before.
player = game.Players.Player1 --Declares a player DSS = game:GetService("DataStoreService")--Declare the Data Store Service PlayerStore = DSS:GetDataSotre(player.Name.."'s DataStores") if PlayerStore:GetAsync(player.Name.."'s stats") == nil then --Uses :GetAsync to find out if the stat hasn't been saved before PlayerStore:SetAsync(player.Name.."'s stats",player.leaderstats.Cash.Value) --Saves the Cash. end