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:
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.
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?
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.
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
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
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!