← resources/ system / datastore-queue
FREE
DataStore queue + retry
Batched, rate-limit-aware DataStore writes with exponential-backoff retry and a simple session lock. Stops data loss under load.
DataStoreQueue.luaupreview — first 10 of 39 lines
--!strict-- DataStoreQueue — batched, retry-aware writes with a simple session lock.local DataStoreService = game:GetService("DataStoreService")local store = DataStoreService:GetDataStore("PlayerData")local Queue = {}local pending: { [string]: any } = {}local locks: { [string]: boolean } = {}local MAX_RETRIES = 5local function withRetry(fn) for attempt = 1, MAX_RETRIES do local ok, res = pcall(fn) if ok then return true, res end task.wait(2 ^ attempt * 0.1) end return falseendfunction Queue.set(key: string, value: any) pending[key] = valueendfunction Queue.flush(key: string) if locks[key] then return end local value = pending[key] if value == nil then return end locks[key] = true local ok = withRetry(function() store:UpdateAsync(key, function() return value end) end) pending[key] = nil locks[key] = nil return okendreturn Queue