DataStore Queue

I have a game where you can buy cash. But when I was testing how much you could buy, I ended up filling the queue and dropping some requests. You can probably figure out this is bad because I don’t want users wasting their Robux for anything.

I came up with an idea for a custom datastore queue but I can’t figure out how to make it work

local DataStore = game:GetService("DataStoreService"):GetDataStore("Data")

local Queue = {}

game:GetService("MarketplaceService").ProcessReceipt = function(info)
     --In code it checks to give the right player the right amount
     table.insert(Queue,{info.PlayerId,info.ProductId})
     DataStore:SetAsync(info.PlayerId .. "+Cash")
end)

I have no clue where to start? Please help, thanks.

If it’s possible to fill the DataStore Queue with your implementation, you could do one of two things:

The more manual route is to write a cache. Every receipt process, you will increment the cash within the cache. The cache would look something like this:

local Cache = {}

MarketPlaceService.ProcessReceipt = function(info)
    if Cache[info.PlayerId] == nil then
        Cache[info.PlayerId] = (some variable corresponding to cash that is awarded from the product)
    else
        Cache[info.PlayerId] += (some variable corresponding to cash that is awarded from the product)
end

OR, you can use a library like ProfileService, which handles this for you. I’d recommend the latter, as it’s quite simple to use, and also has added benefits, such as preventing item duplication and data loss.

You could just save the data when the player leaves, that way it won’t be saving every time they buy cash, but if they are kicked, disconnect or leave in anyway shape or form, their data will save, but it won’t be filling up the datastore queue as much.

This same thing happened to me with the queue yesterday.

To fix it, I used a pcall function when I :SetAsync

Hopefully that’ll work