Hello! Im trying to make a game with Data stores but I keep getting this error:
18:09:50.803 DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 1900786800 - Studio
Also, my DataStores are Not saving, how can I fix this?
local DSS = game:GetService("DataStoreService")
local CurrencyStorage = DSS:GetDataStore("PlayerCurrencyData")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstatsFolder = Instance.new("Folder")
leaderstatsFolder.Name = "leaderstats"
leaderstatsFolder.Parent = plr
local Tix = Instance.new("NumberValue")
Tix.Name = "Tix"
Tix.Parent = leaderstatsFolder
local Robux = Instance.new("NumberValue")
Robux.Name = "Robux"
Robux.Parent = leaderstatsFolder
if CurrencyStorage:GetAsync(plr.UserId) then
Tix.Value = CurrencyStorage:GetAsync(plr.UserId)
Robux.Value = CurrencyStorage:GetAsync(plr.UserId)
else
Tix.Value = 0
Robux.Value = 0
end
Tix:GetPropertyChangedSignal("Value"):Connect(function()
CurrencyStorage:SetAsync(plr.UserId, plr.leaderstats.Tix.Value)
end)
Robux:GetPropertyChangedSignal("Value"):Connect(function()
CurrencyStorage:SetAsync(plr.UserId, plr.leaderstats.Robux.Value)
end)
end)
game.Players.PlayerRemoving:Connect(function(plr)
CurrencyStorage:SetAsync(plr.UserId, plr.leaderstats.Tix.Value)
CurrencyStorage:SetAsync(plr.UserId, plr.leaderstats.Robux.Value)
end)
game:BindToClose(function()
task.wait(1)
for i, v in pairs(game.Players:GetPlayers()) do
CurrencyStorage:SetAsync(v.UserId, v.leaderstats.Tix.Value)
CurrencyStorage:SetAsync(v.UserId, v.leaderstats.Robux.Value)
end
task.wait(3)
end)
Try not using GlobalDataStore:SetAsync function when the value changes. Instead, use it when the player leaves the game and/or you can implement a periodic auto-save.
19:22:09.964 DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 1900786800 - Studio
local DSS = game:GetService("DataStoreService")
local CurrencyStorage = DSS:GetDataStore("PlayerCurrencyData")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstatsFolder = Instance.new("Folder")
leaderstatsFolder.Name = "leaderstats"
leaderstatsFolder.Parent = plr
local Tix = Instance.new("NumberValue")
Tix.Name = "Tix"
Tix.Parent = leaderstatsFolder
local Robux = Instance.new("NumberValue")
Robux.Name = "Robux"
Robux.Parent = leaderstatsFolder
if CurrencyStorage:GetAsync(plr.UserId) then
Tix.Value = CurrencyStorage:GetAsync(plr.UserId)
Robux.Value = CurrencyStorage:GetAsync(plr.UserId)
else
Tix.Value = 0
Robux.Value = 0
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
CurrencyStorage:SetAsync(plr.UserId, plr.leaderstats.Tix.Value)
CurrencyStorage:SetAsync(plr.UserId, plr.leaderstats.Robux.Value)
end)
game:BindToClose(function()
task.wait(1)
for i, v in pairs(game.Players:GetPlayers()) do
CurrencyStorage:SetAsync(v.UserId, v.leaderstats.Tix.Value)
CurrencyStorage:SetAsync(v.UserId, v.leaderstats.Robux.Value)
end
task.wait(3)
end)
local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("DataStoreValues") --Name the DataStore whatever you want
game.Players.PlayerAdded:Connect(function(plr)
local leaderstatsFolder = Instance.new("Folder")
leaderstatsFolder.Name = "leaderstats"
leaderstatsFolder.Name = plr
local Tix = Instance.new("NumberValue")
Tix.Name = "Tix"
Tix.Value = 0
Tix.Parent = leaderstatsFolder
local Robux = Instance.new("NumberValue")
Robux.Name = "Robux"
Robux.Value = 0
Robux.Parent = leaderstatsFolder
local value1Data = Tix
local value2Data = Robux
local s, e = pcall(function()
value1Data = DataStore:GetAsync(plr.UserId.."-Value1") or 0 --check if they have data, if not it'll be "0"
value2Data = DataStore:GetAsync(plr.UserId.."-Value2") or 0
end)
if s then
Tix.Value = value1Data --setting data if its success
Robux.Value = value2Data
else
game:GetService("TestService"):Error(e) --if not success then we error it to the console
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local s, e = pcall(function()
DataStore:SetAsync(player.UserId.."-Value1", plr.leaderstatsFolder.Tix.Value) --setting data
DataStore:SetAsync(player.UserId.."-Value2", plr.leaderstatsFolder.Robux.Value)
end)
if not s then game:GetService("TestService"):Error(e)
end
end)
local DataStoreService = game:GetService("DataStoreService") -- Variable defined for the DataStoreService
local DataStore = DataStoreService:GetDataStore("DataStoreValues") -- This is the name of the DataStore where you are saving the Tix and Robux. You can name it whatever you want, but if you change the name to something different, all the values will reset.
game.Players.PlayerAdded:Connect(function(plr) -- When player joins...
local leaderstatsFolder = Instance.new("Folder") -- Creates the leaderstats
leaderstatsFolder.Name = "leaderstats" -- Name of leaderstats
leaderstatsFolder.Parent = plr -- the leaderstats folder will be under "plr" or "player"
local Tix = Instance.new("NumberValue") -- Creates the Tix Value
Tix.Name = "Tix" -- Name of the Value
Tix.Value = 0 -- Default Value of the Tix. This will be the amount of tix the player will start with.
Tix.Parent = leaderstatsFolder -- The Tix Value will be under the leaderstats folder
local Robux = Instance.new("NumberValue") -- Creates the Robux Value
Robux.Name = "Robux" -- Name of the Value
Robux.Value = 0 -- Default Value of the Robux. This will be the amount of Robux the player will start with.
Robux.Parent = leaderstatsFolder -- The Robux Value will be under the leaderstats folder
-- Defining the variables for the leaderstats values for the DataStore.
local value1Data = Tix
local value2Data = Robux
local s, e = pcall(function() -- This will check and see whether each of the values has any Data in it
value1Data = DataStore:GetAsync(plr.UserId.."-Value1") or 0 --check if the value has data. If it doesn't then the value will be 0.
value2Data = DataStore:GetAsync(plr.UserId.."-Value2") or 0 -- Check if the value has data. If it doesn't then the value will be 0.
end)
if s then -- This means "If success then"
Tix.Value = value1Data -- Setting the Value of the Tix
Robux.Value = value2Data -- Setting the Value of the Robux
else
game:GetService("TestService"):Error(e) -- If the Data fails to save, then an error will appear in the output.
end
end)
game.Players.PlayerRemoving:Connect(function(plr) -- When player leaves
local s, e = pcall(function()
DataStore:SetAsync(player.UserId.."-Value1", plr.leaderstatsFolder.Tix.Value) -- Saving the value of the Tix so when the player rejoins, the amount of tix they have will save.
DataStore:SetAsync(player.UserId.."-Value2", plr.leaderstatsFolder.Robux.Value) -- Saving the Value of the Robux so when the player rejoins the amount of Robux they have will save
end)
if not s then game:GetService("TestService"):Error(e) -- If the Values fail to save, an error will show up in the console.
end
end)
Please note that when I say “Robux” in this script, its not the actual amount of Robux you have in your account. Its just the in-game currency that you named “Robux”.