dataStoreRetry
Provides a utility function to wrap Roblox DataStore API calls with automatic retries for specific, commonly transient error codes.
Purpose: DataStore operations can sometimes fail due to temporary service issues, throttling, or internal errors. This module implements a retry mechanism with exponential backoff to increase the likelihood of success for operations that encounter these transient failures.
Usage:
local DataStoreService = game:GetService("DataStoreService")
local dataStoreRetry = require(script.Parent.dataStoreRetry)
local myStore = DataStoreService:GetDataStore("MyStore")
dataStoreRetry(function()
-- This function will be retried automatically on specific errors
return myStore:GetAsync("MyKey")
end):andThen(function(data)
print("Successfully retrieved data:", data)
end):catch(function(err)
warn("Failed to get data after retries:", err)
end)
Functions
dataStoreRetry
dataStoreRetry.dataStoreRetry(func: () → T--
The function to execute and potentially retry. This function should perform the desired DataStore operation (e.g., GetAsync, SetAsync, UpdateAsync). It should return the result of the operation on success or throw an error on failure.
) → Promise<T>--
A Promise that resolves with the return value of func if it succeeds within MAX_RETRIES attempts.
Wraps a function that performs a DataStore operation, automatically retrying it if it fails with specific transient error codes.
Implements an exponential backoff strategy: waits 1s, 2s, 4s, 8s between retries.
Errors
| Type | Description |
|---|---|
| string | Rejects with the error message if `func` fails with a non-retriable error code, or if it fails with a retriable error code `MAX_RETRIES` times. |