Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

My Datastore script keeps throttling need a fix?

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

1 comment

0

Add a Debounce

1 answer

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.

1 comment

0

I recommend to let the server cache database related stuff too. The server should probably only update the database as less as possible.

This discussion is preserved as it was. New answers, comments, and votes are closed.