I had to turn the game off with 130+ Players... help pls... (DataStore2)

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

1 Like

im not sure but this post feels like it belongs in scripting support

1 Like

Most likely because you are setting/saving the leaderstat value every time it changes. I did the same mistake. Change it so it only saves on player leave

3 Likes