Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I use datastore more efficiently?

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?

1 comment

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.

1 answer

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 comment

1

How would I do this?

This discussion is preserved as it was. New answers, comments, and votes are closed.