Here's some context: I have 32 separate teams (consider them like folders). Each team has 5 distinct values: *wins, losses, touchdowns, field goals, and games played * (consider them like the values within each folder).
I am attempting to save every single value to it's own key, which, if I'm not mistaken, is 160 different keys and 160 different matching values for those keys. This obviously is very cave man brain of me, as I could just save an array instead of individual values. HOWEVER, I have no clue how I would do that in my context.
So if it wasn't obvious beforehand, the requests are piling up like crazy, and the game is suffering because of it. Bear in mind, this is me, an inexperienced programmer, writing moronic code and just rolling with it because of sheer complacency. So I'm absolutely sure that you could point out numerous things wrong here, and I'd appreciate the feedback on any of them.
My main issue is finding a way to lower the requests on the datastore. That's it.
NOTE: There's absolutely nothing "wrong" about this code. It works, however it doesn't work well.
If it's a whole entire process, just tell me that and don't bother coming up with this elaborate answer. But again any feedback is highly appreciated.
Another server script fires this function every 60 seconds.
Here's the code that does the saving:
local sgui = game.Workspace.GameStatisticsBoard.StatisticsGUI -- surface GUI in brick local datamod = require(sgui.DataHandler) --module script with data stored in dictionaries local varaiblemod = require(sgui.VariableHandler) --module script with necessary variables inside local module = {} local DataStoreService = game:GetService("DataStoreService") local DataStore = DataStoreService:GetDataStore("TestStore3") -- datastore module.SaveData = function() for team, statistic in pairs(datamod) do local wins_key = team.."_Wins" local touchdowns_key = team.."_Touchdowns" local fieldgoals_key = team.."_FieldGoals" local losses_key = team.."_Losses" local games_key = team.."_GamesPlayed" DataStore:SetAsync(wins_key, datamod[team].Wins) DataStore:SetAsync(touchdowns_key, datamod[team].Touchdowns) DataStore:SetAsync(fieldgoals_key, datamod[team].FieldGoals) DataStore:SetAsync(losses_key, datamod[team].Losses) DataStore:SetAsync(games_key, datamod[team].GamesPlayed) wait(0.001) end end return module