What's best for data receiving/saving? Loops, or the "standard" method?

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?

1 Like

The best way of saving data is using ProfileService.

That wasn’t the intention of this post. I was wondering the best way to save & receive data through the official service, not through a community-created resource.

I don’t believe any of the data store options can ever be achieve 100% availability. In my opinion, the best option is to retry 3 to 5 times before giving up and notifying the user that data has failed to load.