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

How would i use Data Store?

Asked by
iLegitus 130
9 years ago

So ive made the Data Store script with SH's community people's help,But if i had a GUI,For example a currency gui and i would of liked to access the amount of coins,For example :

script.Parent.Text = RETRIVAL HERE

1 answer

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
9 years ago

You would simply use GetAsync to retrieve the value saved to a particular key. If you want it to update when a key's value is changed, you could also use OnUpdate (However this is throttled, so it may not always update very quickly).

OnUpdate Example:

local DataStore = game:GetService("DataStoreService"):GetDataStore("DataStoreName")

local connection = DataStore:OnUpdate("keyName", function(value)
    script.Parent.Text = value
end)

connection:disconnect() -- Use this when you want it to stop checking for updates

GetAsync Example:

local DataStore = game:GetService("DataStoreService"):GetDataStore("DataStoreName")

script.Parent.Text = DataStore:GetAsync("keyName")
-- This is good if you want to load data when a player enters
Ad

Answer this question