Why does my script stop saving the variable after several dozen commands?

Hello,
Recently I made a quick saving leaderstats script which works fine.
Problems arose when I wanted to add a certain number of points to a player (adding points script)
When the player repeats this command several times, this message is displayed on the output:

DataStore request was added to queue. If request queue fills, further requests will be dropped. Try sending fewer requests.Key = 451472157

When the command repeats approximately 24 times, the writer stops working.

Saving leaderstats script
local dsService = game:GetService("DataStoreService")
local ds = dsService:GetDataStore("MoneyStats")

game.Players.PlayerAdded:Connect(function(plr)
 local folder = Instance.new("Folder", plr)
 folder.Name = "Leaderstats"
 local currency = Instance.new("IntValue", folder)
 currency.Name = "Money"
 currency.Value = ds:GetAsync(plr.UserId) or 0
 currency.Changed:Connect(function()
  ds:SetAsync(plr.UserId, currency.Value)
 end)
end)

game.Players.PlayerRemoving:Connect(function(plr)
 ds:SetAsync(plr.UserId, plr.Leaderstats.Money.Value) 
end)

Adding points script
plr.Leaderstats.Money.Value = plr.Leaderstats.Money.Value+1

I tried to change some script elements, e.g. change it to local script or add RemoteEvent, but it didn’t make sense.

What should I do?

1 Like

You’re sending too many requests out, try saving their stats and updating the leaderboard with local scripts instead and then send a request to update the data store when they leave the experience.

You can see the limit of requests here, as well as errors

You are saving the stats on changed event. Remove that line and only save on PlayerRemoving and BindToClose.

1.What BindToClose means?
2.I deleted " currency.Changed:Connect(function()" and it stopped working completly

Click on the link @TheLegendaryEggMan has sent and read that