OrderedDataStore :GetSortedAsync using all Keys

I’m creating a global leaderboard system using OrderedDataStore and the :GetSortedAsync function but the problem is the :GetSortedAsync function uses all keys that I’ve utilized in the past.
If I update my key from for example ‘player.UserId…“TEST_001”’ to ‘player.UserId…“TEST_002”’, the sorted async still keeps track of the data in ‘player.UserId…“TEST_001”’ and I’m trying to figure out a way around this.

1 Like

You could use string.sub to only show the score if the last few characters of the key does not equal “TEST_001”.

Example:
print(string.sub("metroforce", -5, -1)) --> force

Just want to point out on a side note that you should not save data every 2 seconds, not only will it eat through your data budget incredibly fast but also will eat up your game’s memory, not to mention the errors.

Save using a pcall when main data is saved.