DataStore Question


  • Does this seem like a reasonable way to get data from a datastore?

    local function safeGetAsync(userID, counter)
    	
    	counter = counter or 3
    	
    	if counter > 0 then
    		
    		local success, returnVal
    		
    		if dataStoreService:GetRequestBudgetForRequestType(getAsyncEnum) > 0 then
    			success, returnVal = pcall(mainDataStore.GetAsync, mainDataStore, userID)
    		else
    			
    			repeat
    				wait(1)
    			until dataStoreService:GetRequestBudgetForRequestType(getAsyncEnum) > 0
    			
    			success, returnVal = pcall(mainDataStore.GetAsync, mainDataStore, userID)
    			
    		end
    
    		if success then 
    			return returnVal
    		else
    			return safeGetAsync(userID, counter - 1)
    		end
    		
    	else
    		return "ERROR"
    	end		
    	
    end
    

  • Looks good to me.

Log in to reply
 

Looks like your connection to Scripting Helpers was lost, please wait while we try to reconnect.