YouTube2Text

Ordered DataStore (Global Leaderboards) - Roblox Advanced Scripting #18 — Transcript

by BrawlDev · 5,676 words · 747 segments · language en · Watch on YouTube

Full transcript

  1. 0:00dude I can't even compete with this do
  2. 0:03you see how good these guys are with
  3. 0:04what they do oh man maybe I should give
  4. 0:07myself a year to think about whether
  5. 0:09I'll be getting any further to the top
  6. 0:11of this list or not but I guess we'll
  7. 0:13see what happens I'm going to come back
  8. 0:14in a year from now and see okay it's
  9. 0:16been about a year and I have somewhere
  10. 0:18around 5,000 subscribers so hopefully
  11. 0:20that has brought up my reputation in the
  12. 0:22Roblox developer Community let's
  13. 0:25see wait what the heck bro how did I how
  14. 0:29did my reputation get this bad did I get
  15. 0:31canceled or something oh my God this is
  16. 0:34the worst all right let's think about
  17. 0:36what we just saw for a minute so we have
  18. 0:38this leaderboard and you've probably
  19. 0:40seen these kinds of global leaderboards
  20. 0:42inside of most Roblox games that you can
  21. 0:45think of this is basically a global
  22. 0:47leaderboard and the purpose of This
  23. 0:49Global leaderboard is to display the
  24. 0:52ranking of all the players inside of the
  25. 0:55game across all of the servers within
  26. 0:57the game uh based on a specific leader
  27. 1:00stat which in this case its reputation
  28. 1:03and it's organized in this really neat
  29. 1:05list that displays in descending order
  30. 1:08from the best to the worst and so you
  31. 1:12might ask how is this possible how are
  32. 1:14we able to get every single player uh
  33. 1:17inside of the game that have this leader
  34. 1:19stat and display it across all the
  35. 1:21servers inside of the game well if you
  36. 1:23remember from my previous scripting
  37. 1:25video about data stores which I
  38. 1:27explained right here uh we basically
  39. 1:29have data and then with this data we
  40. 1:31send it over to roblox's servers to be
  41. 1:34able to save it for us so that we can
  42. 1:36retrieve it back whenever uh we need to
  43. 1:38for our specific needs so if we were to
  44. 1:41think about it in This Global
  45. 1:42leaderboard in this case uh we would
  46. 1:44take the data of the player with the
  47. 1:47reputation and then we would send that
  48. 1:49data over to roblox's servers to save it
  49. 1:51for us and if we're in this specific
  50. 1:54game where we need to retrieve the
  51. 1:55information to display it on this
  52. 1:57leaderboard we would send it back over
  53. 1:59to our our game and then display it on
  54. 2:02our screen right here so that is
  55. 2:04essentially how we're able to save data
  56. 2:08send it over to roblox's servers and
  57. 2:09then retrieve it back so that we can
  58. 2:11display it on This Global leaderboard
  59. 2:12now you might ask doesn't this just use
  60. 2:15data stores and to that I say
  61. 2:17technically yes it does use data stores
  62. 2:19but it uses a very specific kind of data
  63. 2:22store called order data stores that
  64. 2:25allows us to display this information in
  65. 2:28this neat list so in this video I'm
  66. 2:30going to show you how we can use these
  67. 2:32ordered data stores inside of a Roblox
  68. 2:34game um to have these organized data
  69. 2:36stores so with that being said let's go
  70. 2:38straight into implementing this inside
  71. 2:40of our Roblox game now that we
  72. 2:42understand it let's start implementing
  73. 2:43ordered data stores but before we do
  74. 2:46make sure that your game is published
  75. 2:48and you have the and you have Studio API
  76. 2:51access and if you don't remember how to
  77. 2:52do that we basically go to home and then
  78. 2:55settings and then over here down to
  79. 2:57security we should have this checked
  80. 2:59enable Studio access to API services and
  81. 3:01then once you have that taken care of
  82. 3:02then we can get start start then we can
  83. 3:04start implementing it okay but now
  84. 3:07because regular data stores don't sort
  85. 3:10their entries we have to do it ourselves
  86. 3:13using a special kind of data store
  87. 3:15called ordered data stores like I
  88. 3:16mentioned earlier so the syntax is going
  89. 3:18to be pretty similar but I'm going to
  90. 3:20try and help you understand what makes
  91. 3:22an ordered data store special in the way
  92. 3:24that an order data store is structured
  93. 3:27but for right now let's go ahead and
  94. 3:28create a script on the right side so
  95. 3:31we're probably going to insert a script
  96. 3:32inside of server script service so let's
  97. 3:34do that and let's delete our print hello
  98. 3:37world okay so first thing we're going to
  99. 3:38do is fetch our data store service so
  100. 3:41that's going to be the same so we're
  101. 3:42going to say local data store service
  102. 3:46equals game colon get
  103. 3:49service open and close parenthesis data
  104. 3:51store service so now that we have that
  105. 3:54we need to access the data store that
  106. 3:57we're trying to uh retrieve so in this
  107. 3:59this case we're going to create a new
  108. 4:00one uh let's just call this player coins
  109. 4:03by using our previous example so we're
  110. 4:04going to say local player coins equals
  111. 4:08data store service now that we have data
  112. 4:11store service we need to access our
  113. 4:13player coins data store but in the past
  114. 4:16we would use what's called get data
  115. 4:19store but in this case we're not trying
  116. 4:21to get a regular data store we're
  117. 4:23actually trying to get an ordered data
  118. 4:25store as displayed down here so we're
  119. 4:28going to say get order data store and
  120. 4:30then it's going to take in two
  121. 4:32parameters one is the name and and then
  122. 4:34the one is the name and the other one is
  123. 4:36a scope but we're not going to use a
  124. 4:37scope for right now we're just going to
  125. 4:38use an order data store name so this one
  126. 4:41is just going to be called player coins
  127. 4:44all right and now we have our ordered
  128. 4:46data store here's the thing that makes
  129. 4:48ordered data stores unique to regular
  130. 4:50data stores so if you remember from my
  131. 4:52leaderboard example we basically have an
  132. 4:54A List full of entries with the key and
  133. 4:57pair values from the data store like
  134. 4:59we've been talking about in the past so
  135. 5:01if I let's say had my player that was up
  136. 5:03here as one entry it would be displayed
  137. 5:06it would be displayed over here but then
  138. 5:08we would have the second entry then the
  139. 5:09third one fourth one fifth one sixth one
  140. 5:11and usually what would happen with these
  141. 5:12order data stores is that we would
  142. 5:14retrieve a specific number of entries
  143. 5:17with within a specific page and speaking
  144. 5:20of pages that is essentially how ordered
  145. 5:23data stores are organized we have a
  146. 5:25specific number of entries that are
  147. 5:28placed within a page and then that data
  148. 5:30story can have multiple Pages like it's
  149. 5:32a book of pages so if I were to go back
  150. 5:34to my script I can show you what this
  151. 5:35would look like so if I were to let's
  152. 5:37say make some comments over here if I
  153. 5:39had a page so this is page one with our
  154. 5:42data store so we're going to have entry
  155. 5:45number one and then entry number two
  156. 5:46entry number three four and then five
  157. 5:48and then let's say we decide to break
  158. 5:50that down into page two so then we would
  159. 5:52have it break down like this with page
  160. 5:55two so then this one is going to
  161. 5:57continue with the number of entries
  162. 5:59which is 6 7 8 9 and then 10 so one
  163. 6:03thing you might have noticed is that
  164. 6:04within each page there is a limit of
  165. 6:07five entries per page and this is
  166. 6:09important to know about when you're
  167. 6:10trying to understand the structure of
  168. 6:12order data stores because this is how we
  169. 6:14break down our data store it's in pages
  170. 6:18and we can access each page if we decide
  171. 6:21to do so so we can choose the limit that
  172. 6:23we want and Roblox will give us the
  173. 6:25number of pages based on how many
  174. 6:27entries there are within this data store
  175. 6:29so if we were to look at once again our
  176. 6:31Global leaderboard our let's say first
  177. 6:34five entries are going to be in this
  178. 6:35page but if we let's say wanted to have
  179. 6:37the second page of data then we would go
  180. 6:39to the sixth entry all the way to the
  181. 6:4110th one for a second page so I hope
  182. 6:43this analogy made a little bit of sense
  183. 6:44to you in understanding how ordered data
  184. 6:47stores are structured so now let's
  185. 6:49continue scripting what we know with
  186. 6:51ordered data stores so I'm going to
  187. 6:52delete this and what we're going to do
  188. 6:55now is hardcode some entries into this
  189. 6:57player coins data store because right
  190. 6:59now it is empty so we want to populate
  191. 7:02it with entries so this isn't a
  192. 7:04practical way of adding these in I'm
  193. 7:06just going to do it for the sake of this
  194. 7:07tutorial so I'm just going to quickly
  195. 7:09put some stuff down here by saying
  196. 7:11player coins colon set async so there's
  197. 7:15no special uh method when it comes to
  198. 7:17order data stores here so we're going to
  199. 7:19give a key which I'm probably just going
  200. 7:21to say my username braw battle and then
  201. 7:23I'm going to put 10 coins inside of here
  202. 7:26and I'm going to do this for maybe two
  203. 7:28more entries so I'm going to say I don't
  204. 7:31know the dev King as as another one and
  205. 7:34I'm going to put Alvin blocks as another
  206. 7:36one down here uh I'm going to give this
  207. 7:39guy 15 coins I'm going to give this guy
  208. 7:4120 coins okay so now we have some
  209. 7:43entries populated within this player
  210. 7:45coin sta store now what we're going to
  211. 7:47do is fetch this information in a page
  212. 7:52so this is basically how it's going to
  213. 7:53work I'm going to drop two lines down
  214. 7:55here we're going to get a table of pages
  215. 7:58with the analogy I just showed you
  216. 7:59earlier by making a variable and setting
  217. 8:02that equal to a return value that gives
  218. 8:05us the list of pages what we're going to
  219. 8:07do is say Local Pages equals player
  220. 8:11coins colon get sorted async open close
  221. 8:17parentheses and there are a bunch of
  222. 8:19arguments here that we can choose when
  223. 8:21it comes to retrieving our Pages inside
  224. 8:25of our player coins data store so this
  225. 8:27first so this first argument here is
  226. 8:29called ascending and this is a Boolean
  227. 8:31value this basically tells us whether we
  228. 8:33want to list these Pages list these
  229. 8:36entries in ascending order or descending
  230. 8:39order so if we go back to our global
  231. 8:41leaders leaderboards example uh this is
  232. 8:43being listed in descending order because
  233. 8:46we're going from the highest values to
  234. 8:47the lowest values but if we're going in
  235. 8:49ascending order we're going to go from
  236. 8:50the lowest values to the highest values
  237. 8:53so in this case let's say we want we
  238. 8:55wanted to go from highest to lowest
  239. 8:58we're going going to we're going to make
  240. 9:00this in descending order so we're going
  241. 9:02to make the Boolean false and so the
  242. 9:04next argument we have is the page size
  243. 9:07which basically tells us how many
  244. 9:09entries do we want to fit within each
  245. 9:11page so from my previous example we had
  246. 9:14five entries for each page so in this
  247. 9:17case let's make it three because we have
  248. 9:19three entries inside of here uh and then
  249. 9:21the next two arguments are basically
  250. 9:23what are the minimum and maximum values
  251. 9:26you want to have for this page uh so if
  252. 9:28we had an entry that was too small let's
  253. 9:31say like let's say for this third entry
  254. 9:32we had zero if we wanted the minimum
  255. 9:34value to be five then this entry will
  256. 9:38not be counted inside of the data store
  257. 9:40because we set a minimum value to five
  258. 9:42and we can basically do the same thing
  259. 9:43with the maximum value being any maximum
  260. 9:46number if there's an entry that goes
  261. 9:48past this maximum number then it's not
  262. 9:50going to show so if we let's say have 10
  263. 9:52then this entry is not going to be
  264. 9:54displayed and you kind of get the idea
  265. 9:56of that but this but for right now we're
  266. 9:58not going to have any restri
  267. 9:59restrictions when it comes to minimum
  268. 10:00and maximum values all we're going to
  269. 10:02have is whether this is as sending or
  270. 10:04descending and we're going to have the
  271. 10:05page size for each page inside of this
  272. 10:08table of pages I hope that part made
  273. 10:10sense to you let's move on to the next
  274. 10:12part now that we have our Pages let's
  275. 10:14try and extract each entry from the page
  276. 10:17that we're currently starting at so in
  277. 10:19this case when we got our Pages it's
  278. 10:21going to start at page one and the way
  279. 10:23we can read the first page of our Pages
  280. 10:26table that we have is by using a
  281. 10:29function called get current page and I'm
  282. 10:31going to show you what this looks like
  283. 10:33so we're going to drop two lines and
  284. 10:34let's say we wanted to get our current
  285. 10:36entries inside of the current page we're
  286. 10:37going to say local entries equals Pages
  287. 10:41colon get current Page open close
  288. 10:44parentheses so with this method we're
  289. 10:46able to get our first three entries
  290. 10:49displayed here because each page has
  291. 10:51three entries as a limit so it's going
  292. 10:54to give us in descending order our
  293. 10:57entries within our player coin data
  294. 10:59store so it's going to start with the
  295. 11:00dev King with 15 coins and then it's
  296. 11:03going to go down to me which is 10 coins
  297. 11:05and it's going to go to Alvin blocks
  298. 11:07which is zero coins so that's basically
  299. 11:09what the page is going to look like and
  300. 11:10so now what we're going to do is print
  301. 11:12out all of these inside of the print out
  302. 11:15all these in the output so that we can
  303. 11:17see it visually so let's go down here
  304. 11:19and as you know entries is a table so we
  305. 11:21want to Loop through all these entries
  306. 11:23that are inside of here so we're going
  307. 11:24to say for rank comma and entry in pairs
  308. 11:30open close parentheses entries do since
  309. 11:34entries is already a table so we have
  310. 11:37our position here which is Rank and then
  311. 11:39we have our entry which is basically our
  312. 11:41key which is basically a dictionary of
  313. 11:44our key and value pair so what we're
  314. 11:46going to do is make a print statement
  315. 11:48for each one by saying print open close
  316. 11:50parenthesis we're going to say Rank and
  317. 11:53then we're going to concatenate this
  318. 11:54using uh using the two dots and then
  319. 11:57we're going to separate this with a Dash
  320. 11:59so that this can be more organized we're
  321. 12:01going to say entry. key which basically
  322. 12:05is which is basically the equivalent of
  323. 12:08our username right here and then we're
  324. 12:10going to separate this with a de with a
  325. 12:13colon so that we can organize this even
  326. 12:14further uh to then say
  327. 12:18entry. value so with each entry they
  328. 12:21have a property F the key and a property
  329. 12:24for the value to be displayed all right
  330. 12:26so I've loaded it into the game and as
  331. 12:28you can see by the output it displayed
  332. 12:30our rank positions uh from starting at
  333. 12:33one so our rank position was at one then
  334. 12:35it went to two and then three but then
  335. 12:37it showed our entry key which is
  336. 12:39basically our username and then finally
  337. 12:41our value for that entry which is the
  338. 12:44the number of coins so the dev King is
  339. 12:46the highest one and then I'm the second
  340. 12:48and then Alam blocks is the third one so
  341. 12:50that is essentially how you can read
  342. 12:52data from each entry that are within
  343. 12:56each page of the data store so so I hope
  344. 12:59you can sort of understand the structure
  345. 13:02of how these ordered data stores work
  346. 13:03because that is how you can uh Implement
  347. 13:06these correctly in your Roblox game okay
  348. 13:08so let's say we did have multiple pages
  349. 13:11so we're not only just trying to get the
  350. 13:13entries from the first page but we're
  351. 13:14going to try to Loop through every
  352. 13:17single page that this data store has to
  353. 13:19offer in order for us to extract the
  354. 13:21information and then display it onto the
  355. 13:23output or whatever else we need it to do
  356. 13:26um we can do that but the first thing we
  357. 13:27need to do is continue to populate our
  358. 13:30player coins data store with more uh
  359. 13:32entries so I'm just going to copy this
  360. 13:34maybe paste like three more so that we
  361. 13:36have a full list of two pages so this
  362. 13:39one could just be Alvin blocks 2 Alvin
  363. 13:42block 3 four I I don't really care at
  364. 13:43this point bro um okay but let's make
  365. 13:47these entries be five six and then seven
  366. 13:50just like something as random as that so
  367. 13:53now we have six entries in our player
  368. 13:54coin sta store so now we need to figure
  369. 13:56out a way to Loop through all all the
  370. 13:59pages that are contained in this data
  371. 14:00store and printed out in the output
  372. 14:02since now we have two pages one of them
  373. 14:05is going to be for the top three spots
  374. 14:07and then the second page is going to be
  375. 14:09for the the the last few spots and we're
  376. 14:12going to be doing this using a while
  377. 14:14loop so we're going to drop two lines
  378. 14:16down here and we're going to say while
  379. 14:18true do and we're actually going to take
  380. 14:21our um our entry Loop through here uh
  381. 14:24and paste it down here so that we're
  382. 14:26going to go and get the current page
  383. 14:28which is the first page and then we're
  384. 14:29going to print out everything that's
  385. 14:31inside of that entry so what we're going
  386. 14:32to do now is drop two lines and we're
  387. 14:34going to check whether we have either
  388. 14:37reached the end of the current page or
  389. 14:40if we're at the very last page because
  390. 14:42if we're at the very last page then we
  391. 14:43can pretty much just terminate this
  392. 14:45while true do Loop because we don't need
  393. 14:47to continue uh searching for entries
  394. 14:49once we've reached the last page we're
  395. 14:51going to use a special property here
  396. 14:53that allows us to do that called is
  397. 14:55finished and this is what it's going to
  398. 14:57look like so we're going to say if Pages
  399. 14:59do is finished then we've basically
  400. 15:03reached the end of our data store so
  401. 15:05we're going to say print uh data store
  402. 15:09is finished and then we're going to hit
  403. 15:12break because we're going to finish this
  404. 15:14while true do statement once we've
  405. 15:16reached the end of our data store list
  406. 15:18but let's say this is not the case let's
  407. 15:20say that we are not at the final page of
  408. 15:23our Page's uh table so we need to move
  409. 15:26on to the next page we're going to use a
  410. 15:28another special method called advance to
  411. 15:30next page so what we're going to do
  412. 15:32instead is we're going to hit else
  413. 15:33because we're not at the final page
  414. 15:35we're going to advance to the next page
  415. 15:37by first printing out a separator so
  416. 15:39that we know that we're going to be at
  417. 15:41the second page then what we're going to
  418. 15:42do is say Pages colon advance to next
  419. 15:48page async open and close parentheses so
  420. 15:50this is the method that we use in order
  421. 15:52to transition to our second page of
  422. 15:55information um but if we already are in
  423. 15:59the last page with the is finished
  424. 16:01property then we're going to break our
  425. 16:03while true do statement now that we know
  426. 16:05that we've went through every single
  427. 16:06entry so that is basically how this
  428. 16:08while true do statement Works in order
  429. 16:10to try and retrieve every single bit of
  430. 16:12information from our pages in inside of
  431. 16:16our data store okay there's one thing I
  432. 16:18forgot to do and that is to move entries
  433. 16:20into our while true do statement we can
  434. 16:23keep the pages up here because we're
  435. 16:24trying to iteratively go through the
  436. 16:26pages as we go through this while
  437. 16:28troducing statement but for our entries
  438. 16:29we need to have it at the very beginning
  439. 16:32uh when we Loop through our data store
  440. 16:34so that's that's a little mess up I did
  441. 16:36uh but now we should be good to join
  442. 16:38into the game and see our result all
  443. 16:40right and as you can see in the output
  444. 16:42we basically have our first three
  445. 16:44entries which has the highest uh which
  446. 16:47has the highest entries since this is
  447. 16:49going in descending orders so we have
  448. 16:51the dev King with 15 coins me with 10
  449. 16:53Alvin blocks four with seven and then we
  450. 16:56transition to the second page that has
  451. 16:59our remaining three entries with six 5
  452. 17:02and zero so that is basically how you
  453. 17:05iterate through multiple Pages going
  454. 17:07through every single one of them so you
  455. 17:08can get every single entry that is
  456. 17:10inside of the data store all right now
  457. 17:12we're at the fun part which is scripting
  458. 17:14a global leaderboard now this isn't
  459. 17:16going to be a step-by-step guide on how
  460. 17:18to create a global leaderboard you can
  461. 17:19just look at somebody else that does it
  462. 17:21we're more interested in scripting the
  463. 17:23global leaderboard rather than actually
  464. 17:25making it so I'm basically using this
  465. 17:27Global leader board that somebody has
  466. 17:29already made um that's pretty organized
  467. 17:31with a surface GUI and also some frames
  468. 17:34that allow us to structure our uh Global
  469. 17:37leaderboard properly so here are a few
  470. 17:39things we need to note before we start
  471. 17:41scripting this so we need to be able to
  472. 17:43see what our template is for each entry
  473. 17:47uh in this leaderboard so it's going to
  474. 17:49be this item so it's going to be this
  475. 17:51Frame called item that basically acts as
  476. 17:53our entry so this is at rank one with
  477. 17:56the player name and then with however
  478. 17:57much money we have over here so there's
  479. 17:59three elements in here that displays the
  480. 18:01information that we need to display uh
  481. 18:04the entry on the global leaderboard so
  482. 18:06this is an important thing to note about
  483. 18:08so we have our container our screen GUI
  484. 18:10and our leaderboard itself so what we're
  485. 18:13going to do is create a script that
  486. 18:15allows us to update this leaderboard
  487. 18:17with uh each entry using this item frame
  488. 18:21so we're going to put a script inside of
  489. 18:23this leaderboard model right here so
  490. 18:24we're going to hit the plus sign here
  491. 18:26and then we're going to insert a script
  492. 18:28so this script is just going to be
  493. 18:29called update
  494. 18:32leaderboard and what we're going to do
  495. 18:34is drag our item so our individual entry
  496. 18:37right here and drag this into our script
  497. 18:40so that we know where to locate it so
  498. 18:42let's open up our update leaderboard
  499. 18:44script let's delete this so first thing
  500. 18:45we're going to do is access our data
  501. 18:48store of course so we're going to copy
  502. 18:50our data store from our previous script
  503. 18:52and then insert that into here now what
  504. 18:54we're going to do is change our data
  505. 18:56store to something different so we could
  506. 18:57probably say player money instead so
  507. 19:00we're going to access an order data
  508. 19:02store called player money instead of
  509. 19:04player coins so let's drop two lines and
  510. 19:07now what we're going to do is make
  511. 19:08reference to uh first our template which
  512. 19:11is going to be the item so we're going
  513. 19:12to say local item equals script colon
  514. 19:18wait for child and then we're going to
  515. 19:20say item and next thing we're going to
  516. 19:22do is locate our player container that
  517. 19:24allows us to put all of our individual
  518. 19:26items inside of the leaderboard so if
  519. 19:29let's say we did take our item and we
  520. 19:32constantly pasted it inside of player
  521. 19:34container it's going to look like this
  522. 19:36but if we duplicate it then it's going
  523. 19:37to automatically uh organize itself to
  524. 19:41be displayed from top to bottom because
  525. 19:42we're using this UI list layout instance
  526. 19:45which you probably don't know about yet
  527. 19:47but we're going to discuss that in a
  528. 19:48future video so that is essentially what
  529. 19:50we're going to do we're basically going
  530. 19:52to get the players uh with their money
  531. 19:55and we're going to uh make an an entry
  532. 19:58an entry frame for each person and put
  533. 20:00it inside of this player container so
  534. 20:02that's the so that's the use case for
  535. 20:04this player container that's why we're
  536. 20:05trying to access it so you're going to
  537. 20:07say local players container equals
  538. 20:11script. parent. leaderboard do
  539. 20:15leaderboard
  540. 20:16gy. leaderboard container. player
  541. 20:20container and there we go now we finally
  542. 20:22have our player container so what we're
  543. 20:23going to do now is create a player added
  544. 20:25event so that we can actually give our
  545. 20:27players some currencies we're going to
  546. 20:29say game. players. player added colon
  547. 20:32connect function player we're going to
  548. 20:34add a leader stats so we're going to say
  549. 20:36local leader stats equals instance. new
  550. 20:41folder and the way we can parent this is
  551. 20:43by putting in a comma and then for the
  552. 20:45second parameter we can put wherever the
  553. 20:46parent is for player so we don't have to
  554. 20:49say leader stats. parent equals player
  555. 20:52we could just simply put in a comma as
  556. 20:54our second argument to know where to put
  557. 20:56this that's a little quick tip to know
  558. 20:58about if you didn't know that so we're
  559. 20:59going to do the same thing with our
  560. 21:01coins uh in value so you're going to say
  561. 21:03local coins equals instance. new in
  562. 21:06value and we're going to put that inside
  563. 21:08of our leader stats oh and my apologies
  564. 21:10I'm supposed to name the leader stats as
  565. 21:12well so I'm going to say leader stats.
  566. 21:13name equals leader stats and we're also
  567. 21:17going to make the coins have a name as
  568. 21:20well with coins okay and so now what
  569. 21:23we're going to do is basically do a
  570. 21:25while true do statement to wait every
  571. 21:28let's say every 10 seconds to save our
  572. 21:32current coins value inside of our player
  573. 21:35money data store and if you remember how
  574. 21:37to properly and securely uh update our
  575. 21:41data store it's by using PE calls so
  576. 21:43we're going to wrap this in a p call by
  577. 21:44saying local success comma error message
  578. 21:49equals P call function open close
  579. 21:52parentheses enter and then what we're
  580. 21:54going to do is say player money Co colon
  581. 21:59set async we're going to pass in the key
  582. 22:02with player. userid and then it's going
  583. 22:05to be the coins. value so it's going to
  584. 22:08be the value of our coins um leader stat
  585. 22:11and we're going to say if not success so
  586. 22:14if it was not successful then what we're
  587. 22:16going to do is print the error message
  588. 22:17so that we know what the error is so now
  589. 22:20we have our basic player added event
  590. 22:22that adds in a uh coins in value and it
  591. 22:25updates it every 10 seconds to the order
  592. 22:29data store so now what we're going to do
  593. 22:31is we're going to write another while
  594. 22:33true do statement to update the actual
  595. 22:35leaderboard itself so we're just going
  596. 22:37to say while true do we're going to wait
  597. 22:4010 seconds uh and now what we're going
  598. 22:42to do is grab our pages so if you
  599. 22:45remember from our previous script we
  600. 22:47grabbed the pages like this using get
  601. 22:49sorted async but we want to do this in a
  602. 22:52more secure way using PE calls so
  603. 22:54instead of doing this what we're going
  604. 22:55to do is say local success Pages equals
  605. 23:00P call function open close parentheses
  606. 23:02enter we're going to say return player
  607. 23:05coins get sorted async false but this
  608. 23:07time we're going to make uh the size 10
  609. 23:10entries per page instead of three and by
  610. 23:12the way it's not player coins it's
  611. 23:13player money this time so now we're able
  612. 23:16to get our Pages successfully and what
  613. 23:17we're going to do is check whether this
  614. 23:19was successful so we're going to say if
  615. 23:21success then we're going to get the
  616. 23:23entries and then Loop through those
  617. 23:25entries so we basically did that in our
  618. 23:26previous script already by first copying
  619. 23:28our entries with get current page and
  620. 23:31then we're going to Loop through all the
  621. 23:32entries inside of that page so we can
  622. 23:34copy this part as well with this for
  623. 23:36Loop so now that we have this we have
  624. 23:38our Rank and we have our entry uh let's
  625. 23:40delete this print statement because we
  626. 23:42don't need it right now so for each
  627. 23:44individual entry we want to make a frame
  628. 23:48and add it to our Global leaderboard so
  629. 23:50the way we're going to do that is take
  630. 23:52our item template and we're going to
  631. 23:53clone it so what we're going to do is
  632. 23:55say local cloned item equals item colon
  633. 24:00clone open close parentheses so this
  634. 24:02basically duplicates our frame so that
  635. 24:04we can add it onto our Global
  636. 24:05leaderboard so before we do that we need
  637. 24:08to uh change the we need to change the
  638. 24:11text of the the rank the player name and
  639. 24:14also how much money they have before
  640. 24:16putting it onto the global leaderboard
  641. 24:18so what we're going to do is fetch the
  642. 24:20players's uh name so that we can display
  643. 24:23it onto here but the thing is with the
  644. 24:24key that we were given it only gives us
  645. 24:27a user ID but it doesn't give us the
  646. 24:29player name so we need to use a special
  647. 24:31function that allows us to get the
  648. 24:34player's name from their user ID and
  649. 24:37players has a function for this for us
  650. 24:39and players has a function that allows
  651. 24:41us to do that so we're going to say
  652. 24:42local username equals game. players
  653. 24:47colon get name from user ID async so
  654. 24:53this is what it's called what we're
  655. 24:54going to do is pass in our uh players's
  656. 24:58user ID which is going to be the entry.
  657. 25:01key if you remember from our first
  658. 25:03script since the key is the player's ID
  659. 25:05and the value is however much money they
  660. 25:08have so we're going to check if this
  661. 25:10username is valid so we're going to say
  662. 25:12if username then what we're going to do
  663. 25:14is update the cloned item uh with it's
  664. 25:17we're going to update the cloned items
  665. 25:19text so we have three text here one for
  666. 25:21the cach one for the name and one for
  667. 25:23the rank so first what we're going to do
  668. 25:24is change the name of the item itself to
  669. 25:26probably the player's name so we're
  670. 25:28going to say cloned item. name equals
  671. 25:32username and then we're also going to
  672. 25:34change the name of the text which we're
  673. 25:36going to say Clon item.
  674. 25:40name item. name text. text since we're
  675. 25:44using the text property we're going to
  676. 25:45set that equal to username so now what
  677. 25:48we're going to do is change the cache
  678. 25:51text and also the rank tech text as well
  679. 25:53so we're going to say clones
  680. 25:55item. cach text. text equals entry.
  681. 26:00value since that's going to be um
  682. 26:01however many coins there is and then the
  683. 26:03rank itself which is going to be
  684. 26:05cloned item. rank text. text equals the
  685. 26:11rank because as you know as we're going
  686. 26:13through our for loop it's also going to
  687. 26:14display the rank as well so that's just
  688. 26:16what we're going to set it to so now
  689. 26:18that we have the entry we need to place
  690. 26:19it inside of the global leaderboard so
  691. 26:21what we're going to do is dropped down
  692. 26:22here and we're simply just going to set
  693. 26:24the parent of the cloned item to the
  694. 26:27players container and boom there we go
  695. 26:31now we have a working Global leaderboard
  696. 26:34script that updates the players uh that
  697. 26:38updates the the player money data store
  698. 26:41based on the coins current based on the
  699. 26:44player coins I should say money instead
  700. 26:46of coins but whatever you get the idea
  701. 26:48and then we're also having another while
  702. 26:51true do statement that updates the
  703. 26:52global leaderboard every 10 seconds to
  704. 26:55check the data store for the top 10
  705. 26:57results and create an entry for each one
  706. 27:01and display it onto the leaderboard and
  707. 27:03we were able to do that successfully
  708. 27:04with PE calls to make it safe all right
  709. 27:06so I'm into the game and after about 10
  710. 27:08seconds it should display my username
  711. 27:10with zero coins as you can see up here
  712. 27:13it displayed the number one spot with my
  713. 27:16player and it also displayed the money
  714. 27:19which is currently zero so if I were to
  715. 27:21go to the uh the server and quickly
  716. 27:24update my coins uh in value to let's say
  717. 27:27100
  718. 27:28uh I'm going to then go back into here
  719. 27:30and then it's going to display my
  720. 27:32character again because we're not
  721. 27:33refreshing the the entries inside of the
  722. 27:35list so that's kind of something we have
  723. 27:37to do as well so that it doesn't
  724. 27:39constantly uh take up all of these
  725. 27:42entries inside of the list so that's
  726. 27:43something we have to do but I think you
  727. 27:45know pretty much up until this point how
  728. 27:47the structure goes so I'm not going to
  729. 27:48go too much into detail about how to
  730. 27:50make a working Global leaderboard
  731. 27:52because you understand the concept of
  732. 27:54order data stores now to be able to
  733. 27:56create your own Global leaderboard and
  734. 27:58also potentially other things you might
  735. 28:01need for for order data stores that
  736. 28:04require you to have an organized list of
  737. 28:06entries within roblox's data stores so I
  738. 28:09hope this video helped you a lot when it
  739. 28:11comes to understanding these ordered
  740. 28:12data stores if you're still sort of
  741. 28:14confused on how data stores work in
  742. 28:16general I encourage you to watch my data
  743. 28:19stores video that I will have for you
  744. 28:21right here but with that being said
  745. 28:22that's going to be it for this episode
  746. 28:24and I will see you in the next one take
  747. 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.