Hello, I am working on a saving system and I’m getting the error message "DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = DiscoveredSpells-1670731971 "
I’m new to DataStores so can someone tell me what I’m doing wrong?
local DataStoreService = game:GetService("DataStoreService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SpellsFolder = ReplicatedStorage:WaitForChild("Spells")
local SpellsDataStore = DataStoreService:GetDataStore("SpellData")
game.Players.PlayerAdded:Connect(function(Player)
local Inventory = Instance.new("Folder",Player)
Inventory.Name = "Inventory"
local DiscoverdSpellsFolder = Instance.new("Folder",Player)
DiscoverdSpellsFolder.Name = "DiscoveredSpells"
local SpellsFolder = Instance.new("Folder",Inventory)
SpellsFolder.Name = "Spells"
local ItemsFolder = Instance.new("Folder",Inventory)
ItemsFolder.Name = "Items"
local PlayerData
local Success,ErrorMessage = pcall(function()
PlayerData = SpellsDataStore:GetAsync("DiscoveredSpells-"..Player.UserId)
end)
if Success and PlayerData then
print("DataStore Success")
for _, SpellName in pairs(PlayerData) do
if DiscoverdSpellsFolder:FindFirstChild(SpellName) then
local SpellValue = Instance.new("StringValue")
SpellValue.Name = SpellName
SpellValue.Parent = DiscoverdSpellsFolder
end
end
else
print("DataStore Error")
warn("ErrorMessage")
end
end)
game.Players.PlayerRemoving:Connect(function(Player)
local SpellsTable = {}
for _, Spell in pairs(Player:WaitForChild("DiscoveredSpells"):GetChildren()) do
table.insert(SpellsTable,Spell.Name)
end
local Success,ErrorMessage = pcall(function()
SpellsDataStore:SetAsync("DiscoveredSpells-"..Player.UserId,SpellsTable)
end)
if Success then
print("DataStore Success")
else
print("DataStore Error")
warn("ErrorMessage")
end
end)
game:BindToClose(function()
for _, Player in pairs(game.Players:GetPlayers()) do
local SpellsTable = {}
for _, Spell in pairs(Player:WaitForChild("DiscoveredSpells"):GetChildren()) do
table.insert(SpellsTable,Spell.Name)
end
local Success,ErrorMessage = pcall(function()
SpellsDataStore:SetAsync("DiscoveredSpells-"..Player.UserId,SpellsTable)
end)
if Success then
print("DataStore Success")
else
print("DataStore Error")
warn("ErrorMessage")
end
end
end)