Weekly Leaderboard

I created a global leaderboard in my game but upon the request of players, they would like a weekly leaderboard that would reset every week whilst not affecting their global stats.

I was thinking that I’d have a script re-make a new datastore, save data to the temporary datastore while updating the global data store, then resetting the temporary one weekly.

In simpler terms, is there a better way to set up a weekly leaderboard for a player’s stats without affecting their permanent amount of points and how would I go about resetting a datastore?


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.

See docs on os.date


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).

For this reason I recommend the first solution.

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.

1 Like

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.