I’m using a BindToClose function in my data store, but every time I leave it freezes and says I’m sending too many datastore requests
This is the function:
I’m using a BindToClose function in my data store, but every time I leave it freezes and says I’m sending too many datastore requests
This is the function:
BindToCkose only “freezes” when you work in studio. Why? Because when you stop play-test, you shut down the server, meaning PlayerRemoving event, if you have it connected, doesn’t fire, thus BindToClose connection is the answer when it comes to saving dats on shut downs.
When this event happens, wrapped code executes as the last set of processes. BindToClose can halt the shutdown for up to 30 seconds. It’s normal and expectrd behaviour.
What about your request queue?
This warning is common, and appear when multiple Data Store write requests for the same key are sent in a short period of time. From information you’ve provided, I cannot know what causes so frequent updating (more rapid than every 6 seconds, which is the limit).
DataStore:SetAsync(key, points)
DataStore:SetAsync(key, hearts)
The above code doesn’t save all the data effectively, nor does it respect the limits.
local data = {["Hearts"] = value; ["Points"] = value}
DataStore:SetAsync(key, data)
-- Access data:
local data = DataStore:GetAsync(key)
data["Hearts"] --> value
I left out protected pcalls() and everything else of course.
e.g. PlayerRemoving, auto-saves and BindToClose.
local lastUpdate = {}
lastUpdate[player here] = os.time()
-- Check whether update has been performed recently:
if (os.time() - lastUpdate[player here] > 6) then
-- safe to continue
lastUpdate[player here] = os.time() -- update time
end
EDIT
PS: Rather use game:GetService(“Players”) and leave out that wait() too.
Thanks, ill try what you suggested