Since there’s no data limit, I would have a permanent location for your player’s points that never changes. And then another datastore that dynamically changes based on the week that tracks points too.
You could literally use the os.date function to grab the week.
The code below should have a unique datastore allocated for each week. It figures this out by creating a unique ID for the week by subtracting the day-of-the-week from the day-of-the-year:
local date = os.date("!*t")
local id = date.year + (date.yday - date.wday)
local storeName = ("points_" .. tostring(id))
local dataStore = dataStoreService:GetDataStore(storeName)
Note: I haven’t thought through all the logic of this code, nor all possible scenarios (e.g. beginning/end of the year). It’s completely untested, but hopefully you get a sense of what I’m thinking could be done.
As far as I understand it, you don’t need to make a temporary DataStore at all.
All you need to do is update the ordered DataStore every time you want to change their weekly stats. You could use it similar to how @Crazyman32 suggested, and have a different ordered DataStore every week.
Or, you could simply embed the weekly data into the player’s main save data (e.g. indexing the current week ID like so: PlayerData.WeeklyData.WeekId) or you could use a completely separate DataStore like crazyman suggested.
This would mean your OrderedDataStore would stay the same however that also means when a new week begins you’ll need to manually reset every saved value in it (because you can’t loop through a DataStore’s contents without making more DataStores).
I scripted a weekly leaderboard earlier this week and I use the exact same week checker method. The leaderboard was cleared today, so it does work as expected. However, I add 1 to the calculation so it updates on Sunday.
When player data saves, I also save the week and a value of the experience they earned during each week which is reset when the week is updated.
Sorry for bumping this old post, i really want to ask. After the leaderboard reset a week later, how do i check the data on the previous week datastore? do i have to run it on a different leaderboard to view it or there is better way to view the data? thank you in advanced.