I have been having issues with datastores recently, I have 7 datastore saving scripts each with intvalues that are in different folders of the player. Could I add a wait some where in the script and change the wait for each script so they save at different periods of time?
Each folder needs to have 30+ maybe even 50-100 intvalues
The scripts all look like this but with different names and stuff:
local ds = game:GetService("DataStoreService"):GetDataStore("APBodyAcc") -- Replace "DataName" with your Data store name you want.
local StatsToAdd = { -- Add or remove stats, You can also set the default start value too.
["VacationLei"] = 0,
["BlueTie"] = 0,
["RedTie"] = 0,
["BlackTie"] = 0,
["ShellBucket"] = 0,
["VipShellBucket"] = 0, --Vip
["DiamondArrow"] = 0, --Chest
["DiamondRing"] = 0, --Chest
["WizardWand"] = 0, --Chest
}
--// Functions
game.Players.PlayerAdded:Connect(function(plr)
local Prefix = plr.UserId
local BodyAcc = Instance.new("Folder", plr)
BodyAcc.Name = "BodyAcc"
for i,v in pairs(StatsToAdd) do -- This will automate the Table for us so we don't need to use Instance alot and changing Values.
local NewInst = Instance.new("IntValue", BodyAcc) -- 2nd Parameter is the Parent of the instance.
NewInst.Name = i
NewInst.Value = v
end
local Data = nil
pcall(function()
Data = ds:GetAsync(Prefix)
end)
if Data ~= nil then
for i,v in pairs(BodyAcc:GetChildren()) do
v.Value = Data[v.Name]
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local Prefix = plr.UserId
local BodyAcc = plr.BodyAcc
pcall(function()
if BodyAcc then
local SaveData = {}
for i,v in pairs(BodyAcc:GetChildren()) do
SaveData[v.Name] = v.Value
end
ds:SetAsync(Prefix, SaveData)
end
end)
end)
Still need help fixing this, I have set the release for a month and idk how to fix this. If I try to play the game while getting the error message the whole game shuts down
Using asynchronous functions alike these on a high rate during a short period of time, will cause these queue issues. Are you saving 30 different data stores? If you do, you could just simply save 1 table of all the player’s data, that’s what I’ve done for many of my statements, and these issues did not appear.
Im using one datastore but accessing from 7 scripts. Im trying to see if I can set up the 7 folders in one script with all the tables there but I am stuck on where to start lol
I thought I was only calling when players join and leave the game to save and load. Im using the int values in the folders for an inventory system and the folders are catagories but that shouldnt be making an issues with data stores.
Im pretty sure, hopefully thats what the code is doing. I just dont see how thats causing the message to go on basically infinitely when I test with 2 players.
game.Players.PlayerAdded:Connect(function(plr)
local Prefix = plr.UserId
local BodyAcc = Instance.new("Folder", plr)
BodyAcc.Name = "BodyAcc"
for i,v in pairs(StatsToAdd) do -- This will automate the Table for us so we don't need to use Instance alot and changing Values.
local NewInst = Instance.new("IntValue", BodyAcc) -- 2nd Parameter is the Parent of the instance.
NewInst.Name = i
NewInst.Value = v
end
local Data = nil
pcall(function()
Data = ds:GetAsync(Prefix)
end)
if Data ~= nil then
for i,v in pairs(BodyAcc:GetChildren()) do
v.Value = Data[v.Name]
end
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local Prefix = plr.UserId
local BodyAcc = plr.BodyAcc
pcall(function()
if BodyAcc then
local SaveData = {}
for i,v in pairs(BodyAcc:GetChildren()) do
SaveData[v.Name] = v.Value
end
Here is how I prevent this:
Use a single slot of datastore, and use the JSON that is in http service, it will turn a table into 1 string, so put all your data into a single table (a table can have mini tables in it), and use this function.
PS: It keeps going indefinitely as your trying to save quite a lot of data there!
For those who are saying that the cause is multiple datastore, the warning will only appear on its specified datastore. So you can only throttle on one datastore, but it won’t throttle the other datastore.
@ramen_rqman You said that you have 7 datastores, right? If so, then you should also take a look at your other datastore script as it might be another datastore that is causing the warning.