Confusion about looping datastores to retry failures

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I want to safeguard my datastores, The best way I see seems to be retrying to data
  2. What is the issue? Include screenshots / videos if possible!
    Since i’m not the best scripter I used a devfourm material (link below) to try to understand but im just not sure how to connect. I mainly dont understand how to take the data from the datastore and bring it into the game if the datastore is successful.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried switching the local success,response part to local data and setting the get async to equal the data but i dont know when to set the value to equal the data. Basically, im really confused
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
    Link to the tutorial for reference: Pcalls - When and how to use them
-- Heres the part of the tutorial i used

local DataStore = game:GetService("DataStoreService"):GetDataStore("MyData")
local success, response --Don't need to define yet
local count = 0 --1

while not success do --2
    if count >= 1 then
        warn("Retrying, count:", count, "\nError:", response) --3
        wait(7) --4

    success, response = pcall(DataStore.GetAsync, DataStore, "key") --5
    count = count + 1 --6

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

Hi, OP of the tutorial here.

In this example the data retrieved from the DataStore will be the response variable, it is named that as it could potentially be an error message when success is false.

Hence, after the while loop your data will be stored in response. Hope this clears any confusion.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.