Ordered DataStore (Global Leaderboards) - Roblox Advanced Scripting #18 — Transcript
Full transcript
- 0:00dude I can't even compete with this do
- 0:03you see how good these guys are with
- 0:04what they do oh man maybe I should give
- 0:07myself a year to think about whether
- 0:09I'll be getting any further to the top
- 0:11of this list or not but I guess we'll
- 0:13see what happens I'm going to come back
- 0:14in a year from now and see okay it's
- 0:16been about a year and I have somewhere
- 0:18around 5,000 subscribers so hopefully
- 0:20that has brought up my reputation in the
- 0:22Roblox developer Community let's
- 0:25see wait what the heck bro how did I how
- 0:29did my reputation get this bad did I get
- 0:31canceled or something oh my God this is
- 0:34the worst all right let's think about
- 0:36what we just saw for a minute so we have
- 0:38this leaderboard and you've probably
- 0:40seen these kinds of global leaderboards
- 0:42inside of most Roblox games that you can
- 0:45think of this is basically a global
- 0:47leaderboard and the purpose of This
- 0:49Global leaderboard is to display the
- 0:52ranking of all the players inside of the
- 0:55game across all of the servers within
- 0:57the game uh based on a specific leader
- 1:00stat which in this case its reputation
- 1:03and it's organized in this really neat
- 1:05list that displays in descending order
- 1:08from the best to the worst and so you
- 1:12might ask how is this possible how are
- 1:14we able to get every single player uh
- 1:17inside of the game that have this leader
- 1:19stat and display it across all the
- 1:21servers inside of the game well if you
- 1:23remember from my previous scripting
- 1:25video about data stores which I
- 1:27explained right here uh we basically
- 1:29have data and then with this data we
- 1:31send it over to roblox's servers to be
- 1:34able to save it for us so that we can
- 1:36retrieve it back whenever uh we need to
- 1:38for our specific needs so if we were to
- 1:41think about it in This Global
- 1:42leaderboard in this case uh we would
- 1:44take the data of the player with the
- 1:47reputation and then we would send that
- 1:49data over to roblox's servers to save it
- 1:51for us and if we're in this specific
- 1:54game where we need to retrieve the
- 1:55information to display it on this
- 1:57leaderboard we would send it back over
- 1:59to our our game and then display it on
- 2:02our screen right here so that is
- 2:04essentially how we're able to save data
- 2:08send it over to roblox's servers and
- 2:09then retrieve it back so that we can
- 2:11display it on This Global leaderboard
- 2:12now you might ask doesn't this just use
- 2:15data stores and to that I say
- 2:17technically yes it does use data stores
- 2:19but it uses a very specific kind of data
- 2:22store called order data stores that
- 2:25allows us to display this information in
- 2:28this neat list so in this video I'm
- 2:30going to show you how we can use these
- 2:32ordered data stores inside of a Roblox
- 2:34game um to have these organized data
- 2:36stores so with that being said let's go
- 2:38straight into implementing this inside
- 2:40of our Roblox game now that we
- 2:42understand it let's start implementing
- 2:43ordered data stores but before we do
- 2:46make sure that your game is published
- 2:48and you have the and you have Studio API
- 2:51access and if you don't remember how to
- 2:52do that we basically go to home and then
- 2:55settings and then over here down to
- 2:57security we should have this checked
- 2:59enable Studio access to API services and
- 3:01then once you have that taken care of
- 3:02then we can get start start then we can
- 3:04start implementing it okay but now
- 3:07because regular data stores don't sort
- 3:10their entries we have to do it ourselves
- 3:13using a special kind of data store
- 3:15called ordered data stores like I
- 3:16mentioned earlier so the syntax is going
- 3:18to be pretty similar but I'm going to
- 3:20try and help you understand what makes
- 3:22an ordered data store special in the way
- 3:24that an order data store is structured
- 3:27but for right now let's go ahead and
- 3:28create a script on the right side so
- 3:31we're probably going to insert a script
- 3:32inside of server script service so let's
- 3:34do that and let's delete our print hello
- 3:37world okay so first thing we're going to
- 3:38do is fetch our data store service so
- 3:41that's going to be the same so we're
- 3:42going to say local data store service
- 3:46equals game colon get
- 3:49service open and close parenthesis data
- 3:51store service so now that we have that
- 3:54we need to access the data store that
- 3:57we're trying to uh retrieve so in this
- 3:59this case we're going to create a new
- 4:00one uh let's just call this player coins
- 4:03by using our previous example so we're
- 4:04going to say local player coins equals
- 4:08data store service now that we have data
- 4:11store service we need to access our
- 4:13player coins data store but in the past
- 4:16we would use what's called get data
- 4:19store but in this case we're not trying
- 4:21to get a regular data store we're
- 4:23actually trying to get an ordered data
- 4:25store as displayed down here so we're
- 4:28going to say get order data store and
- 4:30then it's going to take in two
- 4:32parameters one is the name and and then
- 4:34the one is the name and the other one is
- 4:36a scope but we're not going to use a
- 4:37scope for right now we're just going to
- 4:38use an order data store name so this one
- 4:41is just going to be called player coins
- 4:44all right and now we have our ordered
- 4:46data store here's the thing that makes
- 4:48ordered data stores unique to regular
- 4:50data stores so if you remember from my
- 4:52leaderboard example we basically have an
- 4:54A List full of entries with the key and
- 4:57pair values from the data store like
- 4:59we've been talking about in the past so
- 5:01if I let's say had my player that was up
- 5:03here as one entry it would be displayed
- 5:06it would be displayed over here but then
- 5:08we would have the second entry then the
- 5:09third one fourth one fifth one sixth one
- 5:11and usually what would happen with these
- 5:12order data stores is that we would
- 5:14retrieve a specific number of entries
- 5:17with within a specific page and speaking
- 5:20of pages that is essentially how ordered
- 5:23data stores are organized we have a
- 5:25specific number of entries that are
- 5:28placed within a page and then that data
- 5:30story can have multiple Pages like it's
- 5:32a book of pages so if I were to go back
- 5:34to my script I can show you what this
- 5:35would look like so if I were to let's
- 5:37say make some comments over here if I
- 5:39had a page so this is page one with our
- 5:42data store so we're going to have entry
- 5:45number one and then entry number two
- 5:46entry number three four and then five
- 5:48and then let's say we decide to break
- 5:50that down into page two so then we would
- 5:52have it break down like this with page
- 5:55two so then this one is going to
- 5:57continue with the number of entries
- 5:59which is 6 7 8 9 and then 10 so one
- 6:03thing you might have noticed is that
- 6:04within each page there is a limit of
- 6:07five entries per page and this is
- 6:09important to know about when you're
- 6:10trying to understand the structure of
- 6:12order data stores because this is how we
- 6:14break down our data store it's in pages
- 6:18and we can access each page if we decide
- 6:21to do so so we can choose the limit that
- 6:23we want and Roblox will give us the
- 6:25number of pages based on how many
- 6:27entries there are within this data store
- 6:29so if we were to look at once again our
- 6:31Global leaderboard our let's say first
- 6:34five entries are going to be in this
- 6:35page but if we let's say wanted to have
- 6:37the second page of data then we would go
- 6:39to the sixth entry all the way to the
- 6:4110th one for a second page so I hope
- 6:43this analogy made a little bit of sense
- 6:44to you in understanding how ordered data
- 6:47stores are structured so now let's
- 6:49continue scripting what we know with
- 6:51ordered data stores so I'm going to
- 6:52delete this and what we're going to do
- 6:55now is hardcode some entries into this
- 6:57player coins data store because right
- 6:59now it is empty so we want to populate
- 7:02it with entries so this isn't a
- 7:04practical way of adding these in I'm
- 7:06just going to do it for the sake of this
- 7:07tutorial so I'm just going to quickly
- 7:09put some stuff down here by saying
- 7:11player coins colon set async so there's
- 7:15no special uh method when it comes to
- 7:17order data stores here so we're going to
- 7:19give a key which I'm probably just going
- 7:21to say my username braw battle and then
- 7:23I'm going to put 10 coins inside of here
- 7:26and I'm going to do this for maybe two
- 7:28more entries so I'm going to say I don't
- 7:31know the dev King as as another one and
- 7:34I'm going to put Alvin blocks as another
- 7:36one down here uh I'm going to give this
- 7:39guy 15 coins I'm going to give this guy
- 7:4120 coins okay so now we have some
- 7:43entries populated within this player
- 7:45coin sta store now what we're going to
- 7:47do is fetch this information in a page
- 7:52so this is basically how it's going to
- 7:53work I'm going to drop two lines down
- 7:55here we're going to get a table of pages
- 7:58with the analogy I just showed you
- 7:59earlier by making a variable and setting
- 8:02that equal to a return value that gives
- 8:05us the list of pages what we're going to
- 8:07do is say Local Pages equals player
- 8:11coins colon get sorted async open close
- 8:17parentheses and there are a bunch of
- 8:19arguments here that we can choose when
- 8:21it comes to retrieving our Pages inside
- 8:25of our player coins data store so this
- 8:27first so this first argument here is
- 8:29called ascending and this is a Boolean
- 8:31value this basically tells us whether we
- 8:33want to list these Pages list these
- 8:36entries in ascending order or descending
- 8:39order so if we go back to our global
- 8:41leaders leaderboards example uh this is
- 8:43being listed in descending order because
- 8:46we're going from the highest values to
- 8:47the lowest values but if we're going in
- 8:49ascending order we're going to go from
- 8:50the lowest values to the highest values
- 8:53so in this case let's say we want we
- 8:55wanted to go from highest to lowest
- 8:58we're going going to we're going to make
- 9:00this in descending order so we're going
- 9:02to make the Boolean false and so the
- 9:04next argument we have is the page size
- 9:07which basically tells us how many
- 9:09entries do we want to fit within each
- 9:11page so from my previous example we had
- 9:14five entries for each page so in this
- 9:17case let's make it three because we have
- 9:19three entries inside of here uh and then
- 9:21the next two arguments are basically
- 9:23what are the minimum and maximum values
- 9:26you want to have for this page uh so if
- 9:28we had an entry that was too small let's
- 9:31say like let's say for this third entry
- 9:32we had zero if we wanted the minimum
- 9:34value to be five then this entry will
- 9:38not be counted inside of the data store
- 9:40because we set a minimum value to five
- 9:42and we can basically do the same thing
- 9:43with the maximum value being any maximum
- 9:46number if there's an entry that goes
- 9:48past this maximum number then it's not
- 9:50going to show so if we let's say have 10
- 9:52then this entry is not going to be
- 9:54displayed and you kind of get the idea
- 9:56of that but this but for right now we're
- 9:58not going to have any restri
- 9:59restrictions when it comes to minimum
- 10:00and maximum values all we're going to
- 10:02have is whether this is as sending or
- 10:04descending and we're going to have the
- 10:05page size for each page inside of this
- 10:08table of pages I hope that part made
- 10:10sense to you let's move on to the next
- 10:12part now that we have our Pages let's
- 10:14try and extract each entry from the page
- 10:17that we're currently starting at so in
- 10:19this case when we got our Pages it's
- 10:21going to start at page one and the way
- 10:23we can read the first page of our Pages
- 10:26table that we have is by using a
- 10:29function called get current page and I'm
- 10:31going to show you what this looks like
- 10:33so we're going to drop two lines and
- 10:34let's say we wanted to get our current
- 10:36entries inside of the current page we're
- 10:37going to say local entries equals Pages
- 10:41colon get current Page open close
- 10:44parentheses so with this method we're
- 10:46able to get our first three entries
- 10:49displayed here because each page has
- 10:51three entries as a limit so it's going
- 10:54to give us in descending order our
- 10:57entries within our player coin data
- 10:59store so it's going to start with the
- 11:00dev King with 15 coins and then it's
- 11:03going to go down to me which is 10 coins
- 11:05and it's going to go to Alvin blocks
- 11:07which is zero coins so that's basically
- 11:09what the page is going to look like and
- 11:10so now what we're going to do is print
- 11:12out all of these inside of the print out
- 11:15all these in the output so that we can
- 11:17see it visually so let's go down here
- 11:19and as you know entries is a table so we
- 11:21want to Loop through all these entries
- 11:23that are inside of here so we're going
- 11:24to say for rank comma and entry in pairs
- 11:30open close parentheses entries do since
- 11:34entries is already a table so we have
- 11:37our position here which is Rank and then
- 11:39we have our entry which is basically our
- 11:41key which is basically a dictionary of
- 11:44our key and value pair so what we're
- 11:46going to do is make a print statement
- 11:48for each one by saying print open close
- 11:50parenthesis we're going to say Rank and
- 11:53then we're going to concatenate this
- 11:54using uh using the two dots and then
- 11:57we're going to separate this with a Dash
- 11:59so that this can be more organized we're
- 12:01going to say entry. key which basically
- 12:05is which is basically the equivalent of
- 12:08our username right here and then we're
- 12:10going to separate this with a de with a
- 12:13colon so that we can organize this even
- 12:14further uh to then say
- 12:18entry. value so with each entry they
- 12:21have a property F the key and a property
- 12:24for the value to be displayed all right
- 12:26so I've loaded it into the game and as
- 12:28you can see by the output it displayed
- 12:30our rank positions uh from starting at
- 12:33one so our rank position was at one then
- 12:35it went to two and then three but then
- 12:37it showed our entry key which is
- 12:39basically our username and then finally
- 12:41our value for that entry which is the
- 12:44the number of coins so the dev King is
- 12:46the highest one and then I'm the second
- 12:48and then Alam blocks is the third one so
- 12:50that is essentially how you can read
- 12:52data from each entry that are within
- 12:56each page of the data store so so I hope
- 12:59you can sort of understand the structure
- 13:02of how these ordered data stores work
- 13:03because that is how you can uh Implement
- 13:06these correctly in your Roblox game okay
- 13:08so let's say we did have multiple pages
- 13:11so we're not only just trying to get the
- 13:13entries from the first page but we're
- 13:14going to try to Loop through every
- 13:17single page that this data store has to
- 13:19offer in order for us to extract the
- 13:21information and then display it onto the
- 13:23output or whatever else we need it to do
- 13:26um we can do that but the first thing we
- 13:27need to do is continue to populate our
- 13:30player coins data store with more uh
- 13:32entries so I'm just going to copy this
- 13:34maybe paste like three more so that we
- 13:36have a full list of two pages so this
- 13:39one could just be Alvin blocks 2 Alvin
- 13:42block 3 four I I don't really care at
- 13:43this point bro um okay but let's make
- 13:47these entries be five six and then seven
- 13:50just like something as random as that so
- 13:53now we have six entries in our player
- 13:54coin sta store so now we need to figure
- 13:56out a way to Loop through all all the
- 13:59pages that are contained in this data
- 14:00store and printed out in the output
- 14:02since now we have two pages one of them
- 14:05is going to be for the top three spots
- 14:07and then the second page is going to be
- 14:09for the the the last few spots and we're
- 14:12going to be doing this using a while
- 14:14loop so we're going to drop two lines
- 14:16down here and we're going to say while
- 14:18true do and we're actually going to take
- 14:21our um our entry Loop through here uh
- 14:24and paste it down here so that we're
- 14:26going to go and get the current page
- 14:28which is the first page and then we're
- 14:29going to print out everything that's
- 14:31inside of that entry so what we're going
- 14:32to do now is drop two lines and we're
- 14:34going to check whether we have either
- 14:37reached the end of the current page or
- 14:40if we're at the very last page because
- 14:42if we're at the very last page then we
- 14:43can pretty much just terminate this
- 14:45while true do Loop because we don't need
- 14:47to continue uh searching for entries
- 14:49once we've reached the last page we're
- 14:51going to use a special property here
- 14:53that allows us to do that called is
- 14:55finished and this is what it's going to
- 14:57look like so we're going to say if Pages
- 14:59do is finished then we've basically
- 15:03reached the end of our data store so
- 15:05we're going to say print uh data store
- 15:09is finished and then we're going to hit
- 15:12break because we're going to finish this
- 15:14while true do statement once we've
- 15:16reached the end of our data store list
- 15:18but let's say this is not the case let's
- 15:20say that we are not at the final page of
- 15:23our Page's uh table so we need to move
- 15:26on to the next page we're going to use a
- 15:28another special method called advance to
- 15:30next page so what we're going to do
- 15:32instead is we're going to hit else
- 15:33because we're not at the final page
- 15:35we're going to advance to the next page
- 15:37by first printing out a separator so
- 15:39that we know that we're going to be at
- 15:41the second page then what we're going to
- 15:42do is say Pages colon advance to next
- 15:48page async open and close parentheses so
- 15:50this is the method that we use in order
- 15:52to transition to our second page of
- 15:55information um but if we already are in
- 15:59the last page with the is finished
- 16:01property then we're going to break our
- 16:03while true do statement now that we know
- 16:05that we've went through every single
- 16:06entry so that is basically how this
- 16:08while true do statement Works in order
- 16:10to try and retrieve every single bit of
- 16:12information from our pages in inside of
- 16:16our data store okay there's one thing I
- 16:18forgot to do and that is to move entries
- 16:20into our while true do statement we can
- 16:23keep the pages up here because we're
- 16:24trying to iteratively go through the
- 16:26pages as we go through this while
- 16:28troducing statement but for our entries
- 16:29we need to have it at the very beginning
- 16:32uh when we Loop through our data store
- 16:34so that's that's a little mess up I did
- 16:36uh but now we should be good to join
- 16:38into the game and see our result all
- 16:40right and as you can see in the output
- 16:42we basically have our first three
- 16:44entries which has the highest uh which
- 16:47has the highest entries since this is
- 16:49going in descending orders so we have
- 16:51the dev King with 15 coins me with 10
- 16:53Alvin blocks four with seven and then we
- 16:56transition to the second page that has
- 16:59our remaining three entries with six 5
- 17:02and zero so that is basically how you
- 17:05iterate through multiple Pages going
- 17:07through every single one of them so you
- 17:08can get every single entry that is
- 17:10inside of the data store all right now
- 17:12we're at the fun part which is scripting
- 17:14a global leaderboard now this isn't
- 17:16going to be a step-by-step guide on how
- 17:18to create a global leaderboard you can
- 17:19just look at somebody else that does it
- 17:21we're more interested in scripting the
- 17:23global leaderboard rather than actually
- 17:25making it so I'm basically using this
- 17:27Global leader board that somebody has
- 17:29already made um that's pretty organized
- 17:31with a surface GUI and also some frames
- 17:34that allow us to structure our uh Global
- 17:37leaderboard properly so here are a few
- 17:39things we need to note before we start
- 17:41scripting this so we need to be able to
- 17:43see what our template is for each entry
- 17:47uh in this leaderboard so it's going to
- 17:49be this item so it's going to be this
- 17:51Frame called item that basically acts as
- 17:53our entry so this is at rank one with
- 17:56the player name and then with however
- 17:57much money we have over here so there's
- 17:59three elements in here that displays the
- 18:01information that we need to display uh
- 18:04the entry on the global leaderboard so
- 18:06this is an important thing to note about
- 18:08so we have our container our screen GUI
- 18:10and our leaderboard itself so what we're
- 18:13going to do is create a script that
- 18:15allows us to update this leaderboard
- 18:17with uh each entry using this item frame
- 18:21so we're going to put a script inside of
- 18:23this leaderboard model right here so
- 18:24we're going to hit the plus sign here
- 18:26and then we're going to insert a script
- 18:28so this script is just going to be
- 18:29called update
- 18:32leaderboard and what we're going to do
- 18:34is drag our item so our individual entry
- 18:37right here and drag this into our script
- 18:40so that we know where to locate it so
- 18:42let's open up our update leaderboard
- 18:44script let's delete this so first thing
- 18:45we're going to do is access our data
- 18:48store of course so we're going to copy
- 18:50our data store from our previous script
- 18:52and then insert that into here now what
- 18:54we're going to do is change our data
- 18:56store to something different so we could
- 18:57probably say player money instead so
- 19:00we're going to access an order data
- 19:02store called player money instead of
- 19:04player coins so let's drop two lines and
- 19:07now what we're going to do is make
- 19:08reference to uh first our template which
- 19:11is going to be the item so we're going
- 19:12to say local item equals script colon
- 19:18wait for child and then we're going to
- 19:20say item and next thing we're going to
- 19:22do is locate our player container that
- 19:24allows us to put all of our individual
- 19:26items inside of the leaderboard so if
- 19:29let's say we did take our item and we
- 19:32constantly pasted it inside of player
- 19:34container it's going to look like this
- 19:36but if we duplicate it then it's going
- 19:37to automatically uh organize itself to
- 19:41be displayed from top to bottom because
- 19:42we're using this UI list layout instance
- 19:45which you probably don't know about yet
- 19:47but we're going to discuss that in a
- 19:48future video so that is essentially what
- 19:50we're going to do we're basically going
- 19:52to get the players uh with their money
- 19:55and we're going to uh make an an entry
- 19:58an entry frame for each person and put
- 20:00it inside of this player container so
- 20:02that's the so that's the use case for
- 20:04this player container that's why we're
- 20:05trying to access it so you're going to
- 20:07say local players container equals
- 20:11script. parent. leaderboard do
- 20:15leaderboard
- 20:16gy. leaderboard container. player
- 20:20container and there we go now we finally
- 20:22have our player container so what we're
- 20:23going to do now is create a player added
- 20:25event so that we can actually give our
- 20:27players some currencies we're going to
- 20:29say game. players. player added colon
- 20:32connect function player we're going to
- 20:34add a leader stats so we're going to say
- 20:36local leader stats equals instance. new
- 20:41folder and the way we can parent this is
- 20:43by putting in a comma and then for the
- 20:45second parameter we can put wherever the
- 20:46parent is for player so we don't have to
- 20:49say leader stats. parent equals player
- 20:52we could just simply put in a comma as
- 20:54our second argument to know where to put
- 20:56this that's a little quick tip to know
- 20:58about if you didn't know that so we're
- 20:59going to do the same thing with our
- 21:01coins uh in value so you're going to say
- 21:03local coins equals instance. new in
- 21:06value and we're going to put that inside
- 21:08of our leader stats oh and my apologies
- 21:10I'm supposed to name the leader stats as
- 21:12well so I'm going to say leader stats.
- 21:13name equals leader stats and we're also
- 21:17going to make the coins have a name as
- 21:20well with coins okay and so now what
- 21:23we're going to do is basically do a
- 21:25while true do statement to wait every
- 21:28let's say every 10 seconds to save our
- 21:32current coins value inside of our player
- 21:35money data store and if you remember how
- 21:37to properly and securely uh update our
- 21:41data store it's by using PE calls so
- 21:43we're going to wrap this in a p call by
- 21:44saying local success comma error message
- 21:49equals P call function open close
- 21:52parentheses enter and then what we're
- 21:54going to do is say player money Co colon
- 21:59set async we're going to pass in the key
- 22:02with player. userid and then it's going
- 22:05to be the coins. value so it's going to
- 22:08be the value of our coins um leader stat
- 22:11and we're going to say if not success so
- 22:14if it was not successful then what we're
- 22:16going to do is print the error message
- 22:17so that we know what the error is so now
- 22:20we have our basic player added event
- 22:22that adds in a uh coins in value and it
- 22:25updates it every 10 seconds to the order
- 22:29data store so now what we're going to do
- 22:31is we're going to write another while
- 22:33true do statement to update the actual
- 22:35leaderboard itself so we're just going
- 22:37to say while true do we're going to wait
- 22:4010 seconds uh and now what we're going
- 22:42to do is grab our pages so if you
- 22:45remember from our previous script we
- 22:47grabbed the pages like this using get
- 22:49sorted async but we want to do this in a
- 22:52more secure way using PE calls so
- 22:54instead of doing this what we're going
- 22:55to do is say local success Pages equals
- 23:00P call function open close parentheses
- 23:02enter we're going to say return player
- 23:05coins get sorted async false but this
- 23:07time we're going to make uh the size 10
- 23:10entries per page instead of three and by
- 23:12the way it's not player coins it's
- 23:13player money this time so now we're able
- 23:16to get our Pages successfully and what
- 23:17we're going to do is check whether this
- 23:19was successful so we're going to say if
- 23:21success then we're going to get the
- 23:23entries and then Loop through those
- 23:25entries so we basically did that in our
- 23:26previous script already by first copying
- 23:28our entries with get current page and
- 23:31then we're going to Loop through all the
- 23:32entries inside of that page so we can
- 23:34copy this part as well with this for
- 23:36Loop so now that we have this we have
- 23:38our Rank and we have our entry uh let's
- 23:40delete this print statement because we
- 23:42don't need it right now so for each
- 23:44individual entry we want to make a frame
- 23:48and add it to our Global leaderboard so
- 23:50the way we're going to do that is take
- 23:52our item template and we're going to
- 23:53clone it so what we're going to do is
- 23:55say local cloned item equals item colon
- 24:00clone open close parentheses so this
- 24:02basically duplicates our frame so that
- 24:04we can add it onto our Global
- 24:05leaderboard so before we do that we need
- 24:08to uh change the we need to change the
- 24:11text of the the rank the player name and
- 24:14also how much money they have before
- 24:16putting it onto the global leaderboard
- 24:18so what we're going to do is fetch the
- 24:20players's uh name so that we can display
- 24:23it onto here but the thing is with the
- 24:24key that we were given it only gives us
- 24:27a user ID but it doesn't give us the
- 24:29player name so we need to use a special
- 24:31function that allows us to get the
- 24:34player's name from their user ID and
- 24:37players has a function for this for us
- 24:39and players has a function that allows
- 24:41us to do that so we're going to say
- 24:42local username equals game. players
- 24:47colon get name from user ID async so
- 24:53this is what it's called what we're
- 24:54going to do is pass in our uh players's
- 24:58user ID which is going to be the entry.
- 25:01key if you remember from our first
- 25:03script since the key is the player's ID
- 25:05and the value is however much money they
- 25:08have so we're going to check if this
- 25:10username is valid so we're going to say
- 25:12if username then what we're going to do
- 25:14is update the cloned item uh with it's
- 25:17we're going to update the cloned items
- 25:19text so we have three text here one for
- 25:21the cach one for the name and one for
- 25:23the rank so first what we're going to do
- 25:24is change the name of the item itself to
- 25:26probably the player's name so we're
- 25:28going to say cloned item. name equals
- 25:32username and then we're also going to
- 25:34change the name of the text which we're
- 25:36going to say Clon item.
- 25:40name item. name text. text since we're
- 25:44using the text property we're going to
- 25:45set that equal to username so now what
- 25:48we're going to do is change the cache
- 25:51text and also the rank tech text as well
- 25:53so we're going to say clones
- 25:55item. cach text. text equals entry.
- 26:00value since that's going to be um
- 26:01however many coins there is and then the
- 26:03rank itself which is going to be
- 26:05cloned item. rank text. text equals the
- 26:11rank because as you know as we're going
- 26:13through our for loop it's also going to
- 26:14display the rank as well so that's just
- 26:16what we're going to set it to so now
- 26:18that we have the entry we need to place
- 26:19it inside of the global leaderboard so
- 26:21what we're going to do is dropped down
- 26:22here and we're simply just going to set
- 26:24the parent of the cloned item to the
- 26:27players container and boom there we go
- 26:31now we have a working Global leaderboard
- 26:34script that updates the players uh that
- 26:38updates the the player money data store
- 26:41based on the coins current based on the
- 26:44player coins I should say money instead
- 26:46of coins but whatever you get the idea
- 26:48and then we're also having another while
- 26:51true do statement that updates the
- 26:52global leaderboard every 10 seconds to
- 26:55check the data store for the top 10
- 26:57results and create an entry for each one
- 27:01and display it onto the leaderboard and
- 27:03we were able to do that successfully
- 27:04with PE calls to make it safe all right
- 27:06so I'm into the game and after about 10
- 27:08seconds it should display my username
- 27:10with zero coins as you can see up here
- 27:13it displayed the number one spot with my
- 27:16player and it also displayed the money
- 27:19which is currently zero so if I were to
- 27:21go to the uh the server and quickly
- 27:24update my coins uh in value to let's say
- 27:27100
- 27:28uh I'm going to then go back into here
- 27:30and then it's going to display my
- 27:32character again because we're not
- 27:33refreshing the the entries inside of the
- 27:35list so that's kind of something we have
- 27:37to do as well so that it doesn't
- 27:39constantly uh take up all of these
- 27:42entries inside of the list so that's
- 27:43something we have to do but I think you
- 27:45know pretty much up until this point how
- 27:47the structure goes so I'm not going to
- 27:48go too much into detail about how to
- 27:50make a working Global leaderboard
- 27:52because you understand the concept of
- 27:54order data stores now to be able to
- 27:56create your own Global leaderboard and
- 27:58also potentially other things you might
- 28:01need for for order data stores that
- 28:04require you to have an organized list of
- 28:06entries within roblox's data stores so I
- 28:09hope this video helped you a lot when it
- 28:11comes to understanding these ordered
- 28:12data stores if you're still sort of
- 28:14confused on how data stores work in
- 28:16general I encourage you to watch my data
- 28:19stores video that I will have for you
- 28:21right here but with that being said
- 28:22that's going to be it for this episode
- 28:24and I will see you in the next one take
- 28:26care
About this transcript
This page contains the full transcript of Ordered DataStore (Global Leaderboards) - Roblox Advanced Scripting #18 by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 5,676 words across 747 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.