I had just released my new game and many people were excited to join. However, I had to turn the game off shortly after due to the DataStore2 not being able to keep up. The stats would load after a while or not at all which broke many stuff. It gave the error saying too many requests were being made. Can anyone help me? I’m desperate oof. Did I do something wrong or is DataStore2 not gonna keep up…
local DataStore2 = require(1936396537)
local DefaultValue = 0
game.Players.PlayerAdded:Connect(function(plr)
local skinsTable = {}
local winsDataStore = DataStore2("Wins",plr)
local fragmentsDataStore = DataStore2("SOUL Fragments",plr)
local skinsDataStore = DataStore2("Skins", plr)
local leaderstats = Instance.new("Folder",plr)
leaderstats.Name = "leaderstats"
local purchases = Instance.new("Folder",plr)
purchases.Name = "purchases"
local Wins = Instance.new("IntValue",leaderstats)
Wins.Name = "Wins"
local Fragments = Instance.new("IntValue",leaderstats)
Fragments.Name = "SOUL Fragments"
local function winsUpdate(updatedValue)
Wins.Value = winsDataStore:Get(updatedValue)
end
local function fragmentsUpdate(updatedValue)
Fragments.Value = fragmentsDataStore:Get(updatedValue)
end
local function skinUpdate(updatedValue)
skinsTable = skinsDataStore:Get(updatedValue)
purchases:ClearAllChildren()
for _, skin in pairs(skinsTable) do
local skinValue = Instance.new("BoolValue")
skinValue.Parent = purchases
skinValue.Name = skin
end
end
winsUpdate(DefaultValue)
fragmentsUpdate(DefaultValue)
skinUpdate(skinsTable)
winsDataStore:OnUpdate(winsUpdate)
fragmentsDataStore:OnUpdate(fragmentsUpdate)
skinsDataStore:OnUpdate(skinUpdate)
end)
local Purchases = script.Parent.Purchases
Purchases.ChildAdded:Connect(function(process)
local Product = process.Value
local Price = process.Price.Value
local Buyer = process.Buyer.Value
local Player = game.Players:GetPlayerFromCharacter(Buyer)
local DataStore = DataStore2(“Skins”, Player)
local fragmentsDataStore = DataStore2(“SOUL Fragments”, Player)
local Skins = Player.purchases
local Skin = Instance.new(“BoolValue”)
Skin.Name = Product
Skin.Parent = Skins
local SkinTable = {}
for _, v in ipairs(Skins:GetChildren()) do
table.insert(SkinTable, v.Name)
end
fragmentsDataStore:Increment(-Price,DefaultValue)
DataStore:Set(SkinTable)
end)
local MPS = game:GetService(“MarketplaceService”)
MPS.ProcessReceipt = function(receiptInfo)
if receiptInfo.ProductId == 1265357523 then
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
local fragmentsDataStore = DataStore2(“SOUL Fragments”, player)
fragmentsDataStore:Increment(1250,DefaultValue)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
There seems to be excess calls of Get method. Try to change that.
local function winsUpdate(updatedValue)
Wins.Value = updatedValue
end
local function fragmentsUpdate(updatedValue)
Fragments.Value = updatedValue
end
local function skinUpdate(updatedValue)
skinsTable = updatedValue
purchases:ClearAllChildren()
for _, skin in pairs(skinsTable) do
local skinValue = Instance.new("BoolValue")
skinValue.Parent = purchases
skinValue.Name = skin
end
end
winsUpdate(winsDataStore:Get(updatedValue))
fragmentsUpdate(fragmentsDataStore:Get(updatedValue))
skinUpdate(skinsDataStore:Get(updatedValue))
I am not experienced with any sort of Datastores module (I rely on the orignal Datastores and at most HTTPService). But why are you using so many Datastores.Since you use a Datastore for each value it just uses up more of your requests. I would not advice this for get requests since i see your values are constantly changing but can you just save it at the end of the session? If the player needs to transport between different places then use TeleportData rather than using 2 Requests.I would not recommend this at this point of development but if possible, rewamp your code to have your values updated using Tables. But since you already have players in-game which have well some data, you need to do something about it
I’m 99.9% sure that you’ve fallen victim to a DS2 design flaw that’s causing this heavy throttling. Datastore2 has this function .Combine which basically puts the players data into one huge table which minimalizes the data. (Prevents this massive throttling and data loses) And you here didn’t you it.
TLDR; basically the combine function isn’t called automatically when you start datastore 2 which causes the massive throttling. And you didn’t use the .Combine function
In order to fix this you’ll need to call this function. This is a example post below which uses pseudo code
local datastore2 = [path to the datestore2 module]
datastore2.Combine("Data", "Wins", "Skins", "SOUL Fragments", etc.)
player.PlayerAdded:Connect(function(plr)
local winsDataStore = DataStore2("Wins",plr)
local fragmentsDataStore = DataStore2("SOUL Fragments",plr)
local skinsDataStore = DataStore2("Skins", plr)
--more stuff with the data.
This will remove the throttling when a player loads into the game.
I’ve also seen the replies on your previous post and can ensure you those will not fix the problem. For more information I highly recommend checking out the gotcha page on the DS2 docs. https://kampfkarren.github.io/Roblox/guide/gotchas/
This however will not transfer your previous data and you will need to transfer them yourself. I’ll guide you on how you could transfer data if needed.