I’m trying to efficiently save data using the built-in data store service. With DataStoreService
, there are many ways you can save a data store. The more “unofficial standard” way of using it, as I’ve observed, is doing it directly through the event like the following:
-- // Receive data
local data
local success, result = pcall(function()
data = DataStore:GetAsync(Key)
end)
-- // Save data
local data = Folder.Object.Value
local success, result = pcall(function()
DataStore:UpdateAsync(Key, function()
return data
end)
end)
The way I like to do it is to connect it through a repeat
loop and then set the values depending on what I receive, like the following.
-- // Receive data
local data
local success, result
repeat
success, result = pcall(function()
data = DataStore:GetAsyc(Key)
end)
until success or not game.Players:GetPlayerByUserId(Key)
-- // Save data
local data = Object.Value
local success, result
repeat
DataStore:UpdateAsync(Key, function()
return data
end)
until success
What is, in your opinion, the best way to save data between the two?
Is there anything wrong/good with the methods above?
Do you have any suggestions or methods you use when you’re using data stores?