I’m rewriting a DataStore module I made, and the way I pcall UpdateAsync is like this:
local function RepeatPCall(f, rep)
local TimesRepeated = 0
local success, result
repeat
success, result = pcall(f)
TimesRepeated += 1
wait(0.01) -- Roblox api limit - 1/600 (10x60) =~ 0.0001
until success or TimesRepeated >= rep
return success, result
end
local function DS(Key)
return DataStoreService:GetDataStore(Key)
end
function DataStore:SetAsync(Data, Key, Value)
assert(Data and Key);
local Store = DS(Data)
local success, errormsg = RepeatPCall(function()
Store:UpdateAsync(Key, function(Old)
return Value
end)
end, 10)
return success
end
function DataStore:GetAsync(Data, Key)
assert(Data);
assert(Key);
local Store = DS(Data)
local FinalSuccess, Data = RepeatPCall(function()
return Store:GetAsync(Key)
end, 10)
if FinalSuccess then
return Data
else
return nil
end
end
Full module code is not relevant. (For the ones saying i’m using UpdateAsync plainly if you read my ds code, I use a different version of SetAsync to update player data, this is for initially setting it)