I’m making a global donation leaderboard that features the players with the highest donations. I’m doing this by storing all of the player’s information in a dictionary, though I came across a problem.
When a player donates and becomes the #1 donator, I need to make it so that the previous top donator and all of the other ones featured on the list move a rank down. I’m not quite sure how to do this in the most effective way.
You can just activeGDT["slot"..slot] = activeGDT["slot"..slot-1] given slot > 1. If slot is 1, you’d have to get the last slot’s number instead. Though to be honest, an array-like table is much better for this as it can be iterated and sorted and there’s built in methods to add new data to a specific position.
For example:
local x = {
{UserId: "", Amount: 0},
{UserId: "", Amount: 0},
{UserId: "", Amount: 0},
}
You can use table.sort to sort the table by each value’s Amount value. Or you can iterate until you reach a point where the current value’s Amount is less than whatever amount you want to insert and then insert using table.insert(x, pos, data)
This would be worst way to do this to be honest, why don’t you store donated value inside of just one table and save it through Datastores then use GetOrderedDataStore to make it a global leaderboard depending on how much they donated. If you don’t know how to make a global leaderboard take a look at this: How to make a simple global leaderboard
Alright, Instead of using a normal DataStore, use a OrderedDataStore and save the data to there, with the key as their userid. It’ll get the top donators without going through this trouble. @AtomTostcuOzgurUsta beat me to it lol
Is there a limit to how much data you can put in an OrderedDataStore? I tried to avoid making a value for each player because it would lag and be inefficient in large amounts.