Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I access a data store?

Asked by 10 years ago

I don't need this for a game or anything, since i'm new to data stores, I wanna know how to access a saved data store.

(PS: What are universes?)

1 answer

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

DataStores are like folders for different sets of data. You can create new DataStores and access old ones. How do we create DataStores? We use DataStoreService with the GetDataStore method.

local ds = game:GetService("DataStoreService"):GetDataStore("StoredData")
--[[Here we created a DataStore named 'StoredData', which we can access through the variable 'ds']]--

So how do we get stored data from the DataStore? We use the GetAsync method, with a key that was set previously to define the data. DataStores consist of keys and values, sort of like a dictionary except exponentially larger. When we set a DataStore with SetAsync, then we put the key, and then the wanted data to store. So if we want to retrieve the data then we use GetAsync with that key as the argument.

--First we must set a key of some sort
ds:SetAsync("player_"..game.Players.LocalPlayer.userId, 20)
--[[right here, we set a datastore for the client, with a value of 20.]]--

--Now we can retrieve the data with GetAsync
local data = ds:GetAsync("player_"..game.Players.LocalPlayer.userId)
print(data)
--would print '20', since that's the value that was stored.

You can read more about DataStores Here

0
Thanks for telling me, I finally know what data stores are... Operation_Meme 890 — 10y
Ad

Answer this question