Ive got a script that loads data through the use of a loop. (its a recursive function that loops through folders that contain Int/Bool Values and then loads that data.) there is no more than 50 individual Values that need to be loaded, and it works just fine loading data for one player. The moment that 2 or more players load in, i start to get throttling. I set a cooldown so that after every 30 values that load, it makes the loop wait 6 seconds. Im not sure why its throttling when the amount of times you can use :Get() is
60 + number of players * 10. With 2 players i should be able to call the :Get() function 620 times before throttling, but im only using :Get() 50 times to load data per Player.
does anyone have any tips on perhaps a more efficient way of loading data that what i have?
local DataStore2 = require(1936396537)
local DSS = game:GetService('DataStoreService')
local defaultValue = 0
local CoolDown = 0
local MPS = game:GetService('MarketplaceService')
function CoolDownFunction(Folder,player)
wait(6)
CoolDown = 0
end
function LoopFolder (Folder,Player)
for i,v in pairs(Folder:GetChildren()) do
wait()
if CoolDown >= 30 then
CoolDownFunction(Folder,Player)
end
if v:IsA('Folder') then
LoopFolder(v,Player)
elseif v:IsA('BoolValue') then
v.Value = DataStore2(v.Parent.Name .. v.Name,Player):Get(0 or false)
CoolDown = CoolDown + 1
elseif v:IsA('IntValue') then
v.Value = DataStore2(v.Parent.Name .. v.Name,Player):Get(0 or false)
CoolDown = CoolDown + 1
end
end
end
game.Players.PlayerAdded:Connect(function(player)
repeat wait() until player
local PlayerDataFolder = game.ServerStorage.PlayerData:Clone()
PlayerDataFolder.Parent = game.ServerStorage.PlayerDataFolders
PlayerDataFolder.Name = player.Name
for i,v in pairs(PlayerDataFolder:GetChildren()) do
wait()
if v:IsA('Folder') then
LoopFolder(v,player)
end
end
end)
This isn’t a solution and I may very well be wrong about this; however, simply following order of operations you would multiply first number of players * 10 and then add 60. Hence for two people the limit would be 80.
Nah his code should do the same thing. By PEMDAS, multiplication is automatically first so there’s no need for the parentheses, but I’d use parentheses like you showed anyways for clarification and easier readability
even at that, i set an intvalue to count how many Values were loading, and it always throttles at 50. Does loading and saving data in Studio have some sort of effect on a lower threshold for requests per minute?