Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

My Datastore script keeps throttling need a fix?

Asked by 6 years ago
Edited 6 years ago

I have a slight working data store script but it keeps throttling my stores and i dont know how to fix it, here is my script

local DataStore = game:GetService("DataStoreService")
local ds = DataStore:GetDataStore("CashSaveSystem")

game.Players.PlayerAdded:connect(function(player)
 local leader = Instance.new("Folder",player)
 leader.Name = "leaderstats"
 local Spins = Instance.new("IntValue",leader)
 Spins.Name = "Spins"
 Spins.Value = ds:GetAsync(player.UserId) or 0
 ds:SetAsync(player.UserId, Spins.Value)
 Spins.Changed:connect(function()
  ds:SetAsync(player.UserId, Spins.Value)
 end)
end)


game.Players.PlayerRemoving:connect(function(player)
 ds:SetAsync(player.UserId, player.leaderstats.Spins.Value)
end)


I'm making a simulator game with rapid clicking so it's getting a lot of requests and it's causing it to not save anything. Any help would be appreciated :P

0
Add a Debounce SebbyTheGODKid 198 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

The code you provided wouldn't be throttled. It's only called when a player is added or removed. If you are being throttled, it's because, like you said yourself, you have other code that you didn't post here that is being called many times in a row by clicks. You are exceeding the limits. You'll have to hold back on the requests. Add waits so you can't click many times in a row or cache information locally.

0
I recommend to let the server cache database related stuff too. The server should probably only update the database as less as possible. Zeiver 0 — 6y
Ad

Answer this question