Any way to avoid the 6 seconds cooldown between write requests for the same key in a DataStore?

Due to the complexity of my algorithm, sometimes I need to save the same key in my Datastore in a period of fewer than 6 seconds, which comes up against the imposed limit:

Also, if I want to save the same key before 6 seconds, the routine will yield, thus pausing the game flow.

Is there any way to save the same key before 6 seconds without pausing the game?

2 Likes

What’s your use case?

A general solution is to use a queue or pack data into a storage unit and save that every 6 seconds.

3 Likes

make table and function, which will save things, and if it goes over 6 seconds, instead of saving it will save it in table, and after 6 seconds limit is passed - save your data.

2 Likes

There is no way to bypass the 6 second limit

you have to change your algorithm or use memorystore instead

https://developer.roblox.com/en-us/articles/memory-store

2 Likes

But Memory Store is non-persistent.

You’ll have to get used to it because there is no way, 6 is the limit.

As I believe, currently there is sadly no reason. If this did happen there would be a ‘stack overflow’ where it would fail to run and present an error. You could try to save it after each 6 seconds, if that helps?

That’s correct memorystore last upto 30 days everytime you set the value

So you would need to mix datastore and memorystore to work together

While the server is up and running use the memorystore when the server shuts down save to datastore

But because we have no idea what your doing it’s hard for us to tell you specifics on what to do

My system simulates sending emails to players. I have a DS called Mails, with the UserId as the key and an array for the mails inside that.
In some situations, the same UserId receives more than 1 email in less than 6 seconds, which causes the problem.

You could add the emails into a queue then save them all at once.

1 Like

Here I take the opportunity to ask:
The limit of 6 seconds to record the same key is PER SERVER?
For example: if I have 10 servers trying to save the same key at the same time with a single UpdateAsync each, won’t that throw an error?

this message is incorrect in the old documentation it was not stated that the 6 second limit was a experience wide limit but this has been cleared up in the new documentation

if you want to bypass the 6 second limit I think this is possible using the same technique as datastore2

you can find the source code here Roblox/DataStore2 at master · Kampfkarren/Roblox · GitHub

I personally have not tested this but if I get time ill try to do it and make a video on youtube explaining how to bypass the 6 second limit


the limit is per server so if you have 10 servers then each server can call UpdateAsync every 6 seconds

i think what Vong25 says is the best way
this is how you could have a queue system

local looping = false
local messages = {}

local function Loop()
    local messageData = table.remove(messages, 1)
    if messageData == nil then
        looping = false
    else
        task.delay(6, Loop)
        -- fake code (this is where you add the mail to the datastore)
        -- datastore:update(messageData.to, messageData.text)
    end
end

local function SendMessage(to, text)
    local messageData = {}
    messageData.to = to
    messageData.text = text
    table.insert(messages, messageData)
    if looping == true then return end
    looping = true
    Loop()
end

-- keep the server running for upto 30 seconds after all players have left so we can keep saving any mail in the queue
game:BindToClose(function()
    while #messages > 0 do
        task.wait()
    end
end)

you might want to add a debounce to how often each player can send mail so the queue does not fill up to much

2 Likes

This solution alone was enough to solve the problem.
I didn’t know about task.delay and I was prepared to create a whole manual timing control inside HeartBeat to solve the problem in this topic.
Thank you very much! :smiley:

you can find out more about keeping time here

1 Like