Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How do I fix my data store so it will work?

Asked by 4 years ago
Edited 4 years ago

I'm trying to create a data store to save my cash value. I keep getting this error however. "DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = clothes-8762695" I do have another script running that uses a data store to save the players clothes. Is it causing an error because multiple data stores are running or? Any help would mean a lot. Thanks

local ds = game:GetService("DataStoreService"):GetDataStore("DuhrooLeaderboard13")



game.Players.PlayerAdded:connect(function(player)
local key = "cash-"..player.UserId
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = "Cash"
currency.Value = 1000
currency.Parent = folder

local save = ds:GetAsync(key)

if save then
    currency.Value = save
end

currency.Changed:Connect(function()
ds:SetAsync(currency.Value)
end)
end)

2 answers

Log in to vote
1
Answered by 4 years ago

You should never update datastores more than 2-10 times a minute per player. Obviously if you set an async every time the value is changed this is going to overload the requests for that server. Instead I suggest you save the data when the player leaves and at an interval of about 2 -10 times per minute, depending on the size and number of datastores you would be setting asyncs to. See here for the max requests for different datastore operations

local ds = game:GetService("DataStoreService"):GetDataStore("DuhrooLeaderboard13")



game.Players.PlayerAdded:connect(function(player)
local key = "cash-"..player.UserId
local folder = Instance.new("Folder")
folder.Name = "leaderstats"
folder.Parent = player
local currency = Instance.new("IntValue")
currency.Name = "Cash"
currency.Value = 1000
currency.Parent = folder

local save = ds:GetAsync(key)

if save then
    currency.Value = save
end
-- so again, setting the async everytime it changes will max out the requests so I deleted that connection
end)
-- instead we will update the value when the player leave
game.Players.PlayerRemoving:Connect(function(plyr)
    local key =  "cash-"..player.UserId
    local value = plyr.leaderstats.Cash.Value
    ds:SetAsync(key,value)
end)

To implement a system of updating on time intervals (safer if the set async when the player leaves fails) you would have to save data for players every interval in a while loop or run service connection or some other continuous operation. Also you commented that you were using multiple datastores. Generally I use one datastore and save all the players data in a table because that is more efficient than setting multiple asyncs.

Ad
Log in to vote
-1
Answered by
sheepposu 561 Moderation Voter
4 years ago

That means the datastore is getting too many saves at once. If you are saving a lot of data, you could try saving the data in different datastores. I think that will work. Also "wait()" blocks may fix the problem

0
I am using different data stores for both, different unique Id’s that is. I tried adding wait blocks but still getting the error. Thank you for the help though! cooldrewbie 94 — 4y

Answer this question