When to save data for Leaderboards?

Hey! I have made leaderboards with OOP and now I am at the point of asking myself when I should save the data? Is it better to save the data for 4 datastores upon someone leaves the game or would that break the whole saving when there’s a shutdown for example? Or should I rather loop for every player every 3 minutes to update the ordered datastore?

1 Like

Why on earth would you have 4 datastores? You only need one datastore for leaderboards, maybe two if you wanna seperate the numbered data and everything else. But nothing more than two.

1 Like

It depends how often you want it to update really, I’d say when they leave and every 3 minutes is good - nothing should break when there is a shutdown depending on how you’ve made your system

4 ordered datastores are required to make it 1. more organized and 2. easiere to use since then we’ll have for each leaderboard an own ranking. No need to do extra sorting and all that.

Well I would make either so either the 3 minute save OR once they leave. What would you do because at the moment I am making per leave. This is how it look slike atm:

module.ProcessLeaderboards = function(Plr,Profile)
	task.spawn(function()
		if Profile.Data.Minutes ~= nil and Profile.Data.Minutes ~= 0 then
			DatastoreService:GetOrderedDataStore("MostHours"):SetAsync(Plr.UserId,(Profile.Data.XP / 60))
		end
		if Profile.Data.XP ~= nil and Profile.Data.XP ~= 0 then
			DatastoreService:GetOrderedDataStore("MostXP"):SetAsync(Plr.UserId,Profile.Data.XP)
		end
		if Profile.Data.Tips.Donated ~= nil and Profile.Data.Tips.Donated ~= 0 then
			DatastoreService:GetOrderedDataStore("MostTipsGiven"):SetAsync(Plr.UserId,Profile.Data.Tips.Donated)
		end
		if Profile.Data.Tips.Recieved ~= nil and Profile.Data.Tips.Recieved ~= 0 then
			DatastoreService:GetOrderedDataStore("MostTipsReceived"):SetAsync(Plr.UserId,Profile.Data.Tips.Recieved)
		end
	end)
end

well organization over performance?

That’s why I am here to asking. You are not able to do leaderboards with just 1 Datastore. That’s the whole key purpose of ORDERED Datastores if you wanna take it like this

How dare you talk to me like that? Do you know who I am?

Also how are you using profile stores for leaderboards shouldn’t you just use regula datastoreservice for leaderboards? it’s easier

You could also use a single datastore and have multiple keys per user (User1_Place1Data, User1_Place2Data, etc.), as the docs suggest here

1 Like

No I do not know who you are respectfully and it appears you are not capable to solve this situation with me here. I am using the profile service to gather the data which is saved via profile service. The actual saving of the data for the leaderboards is done via Sorted Datastores. When I enter there multiple keys, it will sort them with the other key’s too resulting in a big mess which is not needed.

If you can’t do both, I would opt for every 3 minutes. If you only update when they leave, a player could stay in game for multiple hours and their leaderboard position not be updated.

1 Like

I was just messing with you to see how you’d react but fair play you didn’t get tempered and throw insults back at me.

Hey @DivScripts,

You should really consider doing both; however, if you are trying to limit how often you save data for whatever reasons… (Both ref to save every so often (e.g. every 3 min) and on leave)

For stats like tips, I don’t see why you wouldn’t save as the stat is updated. There’s no need to save every 3 minutes if the player hasn’t received any tips.

What I would do is save XP and Minutes every 3 to 5 minutes, as well as when the player leaves, while saving tips only when the user receives one.

  • Periodic saves ensure data is regularly backed up in case of crashes or disconnects.
  • Saving on leave captures the final state before the player exits.
  • Using both creates redundancy and ensures better data integrity.

But, I mean, the worst-case scenario is that you’d lose a few minutes of mins tracked / xp if you choose not to save on player leaving. :man_shrugging:

1 Like