So I recently made a topic on an issue with my datastore. Topic
After running some tests on some of my other scripts of code, there is a possible datastore data issue. The problem is that it will always output this message: DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = Data_153362274
It runs correctly, however two different discoveries I made.
- While testing my game in studio, it works correctly. However, while leaving the server will freeze for a brief moment, sending the error message as said above.
- It seems when testing the game from Roblox it functions correctly, however I believe that the server will encounter the same error. I cannot find any evidence, as I cannot experience the output log after leaving the game.
My datastore runs as a table, which was improved from my other way of saving one value at a time. Each value is updated under the table, and is then saved with the datastore, with also another value. This value is known as a ‘key’ which holds the user ID in a format. Example: Key = Data_153362274
. This prevents another user from obtaining the wrong table.
While loading the game, it doesn’t lag, since its only obtaining the values from the table and creating all the required items inside of the player. My theory is:
-
There may be a slower process to save data as a table, since the information inside of that table must be accounted for.
-
The entire saving process is slow. The script must update each value into the table, then send that same information and ‘unpackage’ the data.
Here is my current script I use to save / load my data.
-- Used For Essence, Magic, and Soul Power.
-- Define Values
local DSS = game:GetService("DataStoreService")
local main = DSS:GetDataStore("MainPlayerData")
-- Loads Data
local function load(player)
local savedData = main:GetAsync("Data_"..player.UserId) or {}
local leaderstats = Instance.new("Folder", player)
leaderstats.Name = "leaderstats"
local Essence = Instance.new("IntValue", leaderstats)
Essence.Name = "Essence"
Essence.Value = savedData.Essence
local Magic = Instance.new("IntValue", leaderstats)
Magic.Name = "Magic"
Magic.Value = savedData.Magic
local Soul = Instance.new("IntValue", leaderstats)
Soul.Name = "Soul"
Soul.Value = savedData.Soul
end
-- Saves data
local function save(player)
local key = "Data_"..player.UserId
local s, f = pcall(function()
local leaderstats = player:WaitForChild("leaderstats")
main:UpdateAsync(key, function()
return {
Essence = leaderstats:WaitForChild("Essence").Value,
Magic = leaderstats:WaitForChild("Magic").Value,
Soul = leaderstats:WaitForChild("Soul").Value
}
end)
end)
if not f then
print("Successfully saved "..player.Name.."'s Data ("..player.UserId.."). Key: "..key)
elseif f then
warn("Failed to save "..player.Name.."'s Data ("..player.UserId.."). Key: "..key..". Error: "..f)
end
end
-- Server Shutdown, Saves all data for players in the server.
game:BindToClose(function()
for i, v in pairs(game.Players:GetPlayers()) do
wait()
save(v)
end
end)
-- Calls save/load functions
game.Players.PlayerAdded:Connect(load)
game.Players.PlayerRemoving:Connect(save)
I have attempt to fix the issue with small performance, but the same issue remains. How can I effectively save and load with my datastore without the long shutdown?
This may be in the wrong section, but the datastores taking longer than expected could be a major issue, and may worsen when more tables are added to the datastore.