How to make a datastore for who got badge first ingame? (in order from first to last)

Basically, I have 2 badges that are awarded in 2 different ways in my game (the same game), I wanted to make a script that would basically be a DataStore to make me a list of the username & time of when each person got each badge separately (so basically the datastore would be: BadgeID of the badge gotten - Username of player that got the badge - Time of Getting Badge), I needed it to be in order as in from first to last according to who got the badge first (across all servers, not just the current server). How can I make this? I don’t really know anything about DataStores and I’m a very beginner scripter.

(Normally I wouldn’t have asked for a full script to be made for me on here but I am in a super tight schedule and it is very urgent for me to figure out how to make this script - and since I am a beginner scripter I have no idea what to do :cry:)

2 Likes

You will need to use an ordered data store for that. OrderedDataStore
Many videos online to help you learn this …

3 Likes

Use os.time() and os.date().

os.time() will give you the number of seconds since 1 January 1970, 00:00:00. If you run it right now you’ll get a really large number like 1711071190. You can use this number to compare between players (smaller number means they got the badge sooner).

save each player’s os.time() to an OrderedDataStore (see response above).

To display, retrieve the leaderboard from OrderedDataStore and convert the number into something user readable. Use os.date() for this.

local userTime = os.time() 
print(userTime) -- gives 1711071499

local displayDate = os.date("%c", t) 
print(displayDate) -- gives "Thu Mar 21 20:38:19 2024"
1 Like