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

How can I use datastore more efficiently?

Asked by
trecept 367 Moderation Voter
6 years ago
local level = game:GetService("DataStoreService"):GetDataStore("Level")
local xp = game:GetService("DataStoreService"):GetDataStore("EXP")
local totalxp= game:GetService("DataStoreService"):GetDataStore("totalxp")
local gold = game:GetService("DataStoreService"):GetDataStore("gold")
local win= game:GetService("DataStoreService"):GetDataStore("Wins")
local death= game:GetService("DataStoreService"):GetDataStore("Deaths")

function save(dataname, playerid, value)
    game:GetService("DataStoreService"):GetDataStore(dataname):SetAsync(playerid, value)
end

I've been saving multiple stats like gold, wins, exp like this, and I used to make it so whenever exp changed it would save all the values, and sometimes it was too much for the server to handle.

save("Level",player.UserId,player.leaderstats.Level.Value)
save("EXP",player.UserId,player.EXP.Value)
save("totalxp",player.UserId,player.xpremaining.Value)
save("gold",player.UserId,player.Coins.Value)
save("Wins",player.UserId,player.Wins.Value)
save("Deaths",player.UserId,player.Deaths.Value)

Is there a way to prevent saving issues in the future if it can't all be handled to save all this when the xp is changed or when the player leaves?

0
Try saving the values in one datastore as {Exp = Experience.Value, Lvl = Level.Value, Gold = Gold.Value} etc.you can then read these values out of your table by doing TableName.Exp or TableName.Gold. Also, save once in a while & on disconnect. not every time a value changes. RubenKan 3615 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

You don't need to utilize a seperate datastore for each value. You can simply create a table with the values you want to save and save the table into the datastore.

1
How would I do this? trecept 367 — 6y
Ad

Answer this question