I have a issue with this leaderstats script for my obby game.
I get this error like 3 - 4 times. Any idea how i could fix this?
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local serverStorage = game:GetService("ServerStorage")
local players = game:GetService("Players")
--// Variables \\--
local startTime = os.clock()
local loadTime = ReplicatedStorage:WaitForChild("loadTime")
local serverModulesFolder = ServerScriptService:WaitForChild("ServerModules")
local modules = ReplicatedStorage:WaitForChild("Modules")
local ConfigurationModule = modules:FindFirstChild("Configuration")
local Configuration = require(ConfigurationModule)
local dataStore2Module = serverModulesFolder:WaitForChild("DataStore2")
local dataStore2 = require(dataStore2Module)
local statsVersion = ReplicatedStorage:WaitForChild("gameVersion").Value
local skipId = Configuration.ProductIds.skipId
local stageDataStore = DataStoreService:GetDataStore("StageData_"..statsVersion)
local deathsDataStore = DataStoreService:GetDataStore("DeathsData_"..statsVersion)
local coinsDataStore = DataStoreService:GetDataStore("CoinsData_"..statsVersion)
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"
local stage = Instance.new("IntValue")
stage.Parent = leaderstats
stage.Name = "Stage"
stage.Value = 1
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats
local success, error = pcall(function()
local data = stageDataStore:GetAsync(plr.UserId)
if data then
stage.Value = data.Stage or 1
coins.Value = data.Coins or 0
end
end)
if not success then
warn("Error retrieving player data for "..plr.Name..": "..error)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, error = pcall(function()
local data = {
Stage = plr.leaderstats.Stage.Value,
Coins = plr.leaderstats.Coins.Value
}
stageDataStore:SetAsync(plr.UserId, data)
end)
if not success then
warn("Error saving player data for "..plr.Name..": "..error)
end
end)
MarketplaceService.ProcessReceipt = function(info)
local plr = game.Players:GetPlayerByUserId(info.PlayerId)
if info.ProductId == skipId then
plr.leaderstats.Stage.Value += 1
plr:LoadCharacter()
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
local endTime = os.clock()
local elapsedTime = (endTime - startTime) * 75000
loadTime.Value = elapsedTime
There doesn’t seem to be anything that can cause the queue to fill up in this code, unless either the ConfigurationModule or the dataStore2Module or both are internally using DataStores in a way that would cause them to run when required
That warning shows up if either one of a DataStore’s method is called in rapid succession (could either be GetAsync or SetAsync, most commonly SetAsync is being called too frequently within a loop when data attempts to save or when a server is shutting down)
True, but the warning shouldn’t show up in this case since you’re using SetAsync on different DataStores, although you can try adding a task.wait between each statement as a test if you prefer
btw that code you provided isn’t part of the code you posted originally
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local serverStorage = game:GetService("ServerStorage")
local players = game:GetService("Players")
--// Variables \\--
local startTime = os.clock()
local loadTime = ReplicatedStorage:WaitForChild("loadTime")
local modules = ReplicatedStorage:WaitForChild("Modules")
local ConfigurationModule = modules:FindFirstChild("Configuration")
local Configuration = require(ConfigurationModule)
local statsVersion = ReplicatedStorage:WaitForChild("gameVersion").Value
local skipId = Configuration.ProductIds.skipId
local stageDataStore = DataStoreService:GetDataStore("StageData_"..statsVersion)
local deathsDataStore = DataStoreService:GetDataStore("DeathsData_"..statsVersion)
local coinsDataStore = DataStoreService:GetDataStore("CoinsData_"..statsVersion)
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"
local stage = Instance.new("IntValue")
stage.Parent = leaderstats
stage.Name = "Stage"
stage.Value = 1
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats
local success, error = pcall(function()
local data = stageDataStore:GetAsync(plr.UserId)
if data then
stage.Value = data.Stage or 1
coins.Value = data.Coins or 0
end
end)
if not success then
warn("Error retrieving player data for "..plr.Name..": "..error)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, error = pcall(function()
local data = {
Stage = plr.leaderstats.Stage.Value,
Coins = plr.leaderstats.Coins.Value
-- Add other data you want to save
}
stageDataStore:SetAsync(plr.UserId, data)
end)
if not success then
warn("Error saving player data for "..plr.Name..": "..error)
end
end)
MarketplaceService.ProcessReceipt = function(info)
local plr = game.Players:GetPlayerByUserId(info.PlayerId)
if info.ProductId == skipId then
plr.leaderstats.Stage.Value += 1
plr:LoadCharacter()
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
local endTime = os.clock()
local elapsedTime = (endTime - startTime) * 75000
loadTime.Value = elapsedTime
Yea, i saw that i’m so sorry i copied the wrong code in but this one is the right one:
local ServerScriptService = game:GetService("ServerScriptService")
local ReplicatedStorage = game:GetService('ReplicatedStorage')
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local serverStorage = game:GetService("ServerStorage")
local players = game:GetService("Players")
--// Variables \\--
local startTime = os.clock()
local loadTime = ReplicatedStorage:WaitForChild("loadTime")
local modules = ReplicatedStorage:WaitForChild("Modules")
local ConfigurationModule = modules:FindFirstChild("Configuration")
local Configuration = require(ConfigurationModule)
local statsVersion = ReplicatedStorage:WaitForChild("gameVersion").Value
local skipId = Configuration.ProductIds.skipId
local stageDataStore = DataStoreService:GetDataStore("StageData_"..statsVersion)
local deathsDataStore = DataStoreService:GetDataStore("DeathsData_"..statsVersion)
local coinsDataStore = DataStoreService:GetDataStore("CoinsData_"..statsVersion)
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Parent = plr
leaderstats.Name = "leaderstats"
local stage = Instance.new("IntValue")
stage.Parent = leaderstats
stage.Name = "Stage"
stage.Value = 1
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Value = 0
coins.Parent = leaderstats
local success, error = pcall(function()
local data = stageDataStore:GetAsync(plr.UserId)
if data then
stage.Value = data.Stage or 1
coins.Value = data.Coins or 0
end
end)
if not success then
warn("Error retrieving player data for "..plr.Name..": "..error)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, error = pcall(function()
local data = {
Stage = plr.leaderstats.Stage.Value,
Coins = plr.leaderstats.Coins.Value
-- Add other data you want to save
}
stageDataStore:SetAsync(plr.UserId, data)
end)
if not success then
warn("Error saving player data for "..plr.Name..": "..error)
end
end)
MarketplaceService.ProcessReceipt = function(info)
local plr = game.Players:GetPlayerByUserId(info.PlayerId)
if info.ProductId == skipId then
plr.leaderstats.Stage.Value += 1
plr:LoadCharacter()
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
local endTime = os.clock()
local elapsedTime = (endTime - startTime) * 75000
loadTime.Value = elapsedTime
I got that sometimes too with profile service I think you should wait with sending receust since it says that the queue is full the data store can only handle a certain amount of receusts in a time other it will be rejected that’s what I’ve learnt from @0Shank maybe he can explain more
What I think is that the script send to much receusts maybe it sent a receust each time the os date change
You are making multiple DataStore requests at once, so further requests are being throttled until the other requests have been processed. Are you using a BindToClose so you don’t save the same data twice?
You have exceeded the request budget. All this means is after you exceed the budget, further requests are subject to throttling and will be added to the queue.
Remember, all this warning means is data needs a little more time to save, delay your requests a bit.
Adding onto my previous post, you can use a BindToClose subprogram to make sure you are not spamming the store with duplicate requests.
local runService = game:GetService("RunService")
local players = game:GetService("Players")
game:BindToClose(function()
if runService:IsStudio() or #players:GetPlayers() <= 1 then
task.wait(3)
return nil
end
for _, player in next, players:GetPlayers(), nil do
--[[
Save player data here. I would recommend
converting your PlayerRemoving connection
so it can be used not only to save data on leave
but also to save data on game close.
]]
end
task.wait(3)
end)
you should also use UpdateAsync instead of SetAsync.