What's up with my DataStore?

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.

Delete this:

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)
1 Like

It still saying this even though I changed this.

  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)

You are using the async request many times in a short period of time.

Also your code will just save and load the robux value.

You can try this for both values.

--Save

CurrencyStorage:SetAsync(plr.UserId, {
    Tix = v.leaderstats.Tix.Value,
    Robux = v.leaderstats.Robux.Value
})

--Load

local tab = CurrencyStorage:GetAsync(plr.UserId) or {Robux = 0, Tix = 0}
Tix.Value = tab.Tix
Robux.Value = tab.Robux
3 Likes

Try this:

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)

You should use Robux.Value.Changed:Connect(function()

Can you add comments and explain the script more? Its not very helpful if your trying to help someone but not explain how your example/answer works!

That’s your problem. Every single time it changes, you set it. It overflows the queue. I suggest you just use a table to save multiple values.

This overwrites the data. Use a table like @ancadejo10 demonstrated.

Yes, I will. Take a look now:

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”.

1 Like

Try using Datastore Resource [REMADE] I made it not too long ago.