Data Store is a Roblox Service that allows game developers to save data to the cloud. You can easily send or receive this Data using SetAsync()
or GetAsync()
. The advantage to using Data Store than Data Persistence is that you can load information from any server without the player needing to be there.
Data Store works as a key and value. Notice below how each key has a value. A better image of how its saved is here.
In order to use this service, you would want to call for it;
1 | DataStore = game:GetService( "DataStoreService" ):GetDataStore( "StatsService" ) |
You can name StatsService to anything you want, I just believe that it should possess a relevant name to what you are doing.
In your case, in order to use the script to load WipeOut and KnockOuts leaderboard you would use :GetAsync()
.
01 | game.Players.PlayerAdded:connect( function (player) |
02 | repeat wait() until player:FindFirstChild( "leaderstats" ) |
03 | repeat wait() until player.leaderstats:FindFirstChild( "WipeOuts" ) |
04 | repeat wait() until player.leaderstats:FindFirstChild( "KnockOuts" ) |
06 | local PlrsWipeOuts = DataStore:GetAsync(player.Name .. "_WOs" ) |
07 | local PlrsKnockOuts = DataStore:GetAsync(player.Name .. "_KOs" ) |
10 | if PlrsWipeOuts ~ = nil then |
11 | player.leaderstats.WipeOuts.Value = PlrsWipeOuts |
12 | player.leaderstats.KnockOuts.Value = PlrsKnockOuts |
You can save data by using the .PlayerRemoving Event
and the SetAsync()
function.
Warning, now PlayerRemoving has been known to be buggy when say, the server lags out. So if your game does not require players getting killed easily you can use a .Changed Event
.
01 | game.Players.PlayerRemoving:connect(player) |
02 | if player:FindFirstChild( "leaderstats" ) then |
03 | if player.leaderstats:FindFirstChild( "WipeOuts" ) then |
04 | DataStore:SetAsync(player.Name .. "_WOs" , player.leaderstats.WipeOuts.Value) |
06 | if player.leaderstats:FindFirstChild( "KnockOuts" ) then |
07 | DataStore:SetAsync(player.Name .. "_KOs" , player.leaderstats.KnockOuts.Value) |
Now you have saved the data.
For your script, I am not too familiar with UpdateAsync but I do believe anyone can get by on just using Get/SetAsync()
I hope this helped, if you have any questions feel free to ask on this site. I will ignore scripting questions to me on the ROBLOX site.