YouTube2Text

Gamepasses (One-Time Robux Pass & DataStore Receipt) - Roblox Advanced Scripting #21 (2024) — Transcript

by BrawlDev · 7,248 words · 954 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Bro, who does this guy think he is
  2. 0:02trying to creep up on me? Oh my Wait,
  3. 0:05dude. I'm trying to get away from this
  4. 0:06guy, but it's not working. Bro, he keeps
  5. 0:08following me. What the heck is going on
  6. 0:11right now, dude? I need to get rid of
  7. 0:13this guy somehow, cuz Oh my god, he's
  8. 0:16not going to leave me alone. I noticed
  9. 0:18that as I was looking at this creep, I
  10. 0:20see this thing down here that says,
  11. 0:21"Click me if you're mad." What does this
  12. 0:23thing actually do? Oh, would you like to
  13. 0:26buy banan creep
  14. 0:29for 10 Robux? That's not a bad idea to
  15. 0:32get rid of this guy. All right, let's
  16. 0:34see if I can do that. All right,
  17. 0:35purchase has been successful. Oh, yeah.
  18. 0:39Got rid of him. Thank god. Wait, what?
  19. 0:42He's back. What? Pay to win is a lie.
  20. 0:45Remember that. Oh my god. Are you
  21. 0:49serious right now, bro? All right, let's
  22. 0:52think about this for a minute.
  23. 0:53Unfortunately, I just can't seem to get
  24. 0:55rid of this guy. This guy's just gonna
  25. 0:57have to stick with me this whole time, I
  26. 0:59guess. But anyways, what ended up
  27. 1:01happening was I saw this button down
  28. 1:03here that said, "Click me if you're
  29. 1:05mad." And when I did click on it, uh,
  30. 1:07Roblox prompted this little GUI that I
  31. 1:10did not create. And this basically asks
  32. 1:12me, would I like to buy this item, also
  33. 1:15known as ban creep, for 10 Robux? And
  34. 1:17for whatever reason, if you're not
  35. 1:18familiar with Roblox, it's essentially
  36. 1:20Roblox's universal currency that's used
  37. 1:23across the entire platform that can be
  38. 1:25used to buy these sorts of things. This
  39. 1:27is essentially called a game pass. And
  40. 1:29what this does is when you buy a game
  41. 1:32pass, like right now, uh you buy a game
  42. 1:34pass and what ends up happening is that
  43. 1:36the server uh does something to show
  44. 1:39that you have now bought this game pass.
  45. 1:41So, this game pass can pretty much be uh
  46. 1:44getting access to a specific area in the
  47. 1:47game. Uh it can also just be getting
  48. 1:49some sort of privileged advantage over
  49. 1:51other players. Not too big of an
  50. 1:53advantage, but somewhat of a one-step
  51. 1:56level advantage from other players. And
  52. 1:58the thing about game passes is that it's
  53. 2:00a one-time purchase. So, if you buy a
  54. 2:03game pass, then you don't have to buy it
  55. 2:05ever again if it's on the same account.
  56. 2:08So, let's say I did decide to buy this
  57. 2:10game pass that says, "Would you like to
  58. 2:11buy ignore?" I'm going to buy this for
  59. 2:13one Robux. Uh, the purchase has been
  60. 2:16successful. And then what should happen
  61. 2:17in the game is that I'm given this
  62. 2:20Minecraft diamond sword. Don't don't ask
  63. 2:22me why, but that's basically what ended
  64. 2:25up happening. And since I bought it, I
  65. 2:27don't have to buy it ever again. If I
  66. 2:29reset my character, then what ends up
  67. 2:32happening is that uh the game will check
  68. 2:33if I own this game pass and it will just
  69. 2:36give me this sword again once I refresh
  70. 2:38into the game. So, I ended up getting
  71. 2:40the sword again in my backpack because
  72. 2:42the game checked if I had this game pass
  73. 2:44now that I did buy it. And that is
  74. 2:46basically uh one way of using game
  75. 2:48passes. It's a way for you to get
  76. 2:50specialized privileges within a Roblox
  77. 2:53game that you only have to buy one time.
  78. 2:56And that's what I'm going to be showing
  79. 2:57you how to do in this episode, which is
  80. 2:59creating a game pass, implementing it,
  81. 3:01and keeping track of our players
  82. 3:03purchase history using data stores at
  83. 3:05the end of this video. So, with that
  84. 3:07being said, let's get straight into
  85. 3:09implementing game passes inside of
  86. 3:11Roblox Studio.
  87. 3:13Oh my god, no way. This diamond sword
  88. 3:15actually killed the creep. Oh my god,
  89. 3:17this is incredible. Okay, but anyways,
  90. 3:19let's get straight into implementing.
  91. 3:21Now, now that we understand it, let's
  92. 3:23add game passes into our game. But
  93. 3:25before we do, we need to make sure that
  94. 3:26our game is published. So if you're in a
  95. 3:29local file right now, I want you to go
  96. 3:31on the top left, hit file, and then hit
  97. 3:33publish to Roblox as. And you can
  98. 3:36basically publish this to any game that
  99. 3:38you choose. Uh my game is already
  100. 3:40published, so I don't need to do that.
  101. 3:41But just make sure you do that first
  102. 3:43before we move on to implementing game
  103. 3:45passes. But now that we've gotten that
  104. 3:47taken care of, let's actually create a
  105. 3:48game pass. And you might ask, where do
  106. 3:50we create this game pass? Because if you
  107. 3:52remember from our badges, all we had to
  108. 3:54do is just go to home, go to game
  109. 3:56settings, and then go to monetization.
  110. 3:57But if we come over here, we see that
  111. 4:00there's no game passes. So, where the
  112. 4:02heck do we So, where the heck do we
  113. 4:04create these game passes? We're going to
  114. 4:06have to go to the Roblox website in the
  115. 4:09creator hub uh to create our game passes
  116. 4:12on our creator page. So, that's where
  117. 4:14we're about to be headed, and I'm going
  118. 4:15to meet you there. All right, so we're
  119. 4:17in the homepage of Roblox. In order to
  120. 4:18access our game passes, we need to go to
  121. 4:20our creator hub by clicking on this
  122. 4:22button on the top that says create. This
  123. 4:24will bring up our creator dashboard. And
  124. 4:26so let's look for our game that we've
  125. 4:29just published. In this case, for my
  126. 4:31game, it's called data store test one.
  127. 4:32So we're just going to click on the name
  128. 4:34of it. So this will bring up the entire
  129. 4:38um overview. This will bring up the
  130. 4:40entire creator dashboard of this game.
  131. 4:42So what we want to do is go on the left
  132. 4:44side, go down to monetization, and then
  133. 4:46click on passes. This should give us a
  134. 4:49list of all of our game passes that are
  135. 4:51within the game currently. Uh just
  136. 4:53ignore these two that are here right
  137. 4:55now. Um but this should be blank for you
  138. 4:57if you've created a new game. So in
  139. 4:58order to create a game pass, we need to
  140. 5:00click this button that says create a
  141. 5:01pass. And then it'll bring up a page
  142. 5:04where we can give the name of our game
  143. 5:06pass. We can change the image of it, but
  144. 5:08Roblox will give us an image by default.
  145. 5:10So we don't have to worry too much about
  146. 5:11that. And you can also add a
  147. 5:12description. The only field that's
  148. 5:14required is the name. So let's just do
  149. 5:16that really quick. We're going to call
  150. 5:17this game pass uh test one just to keep
  151. 5:21it simple. Uh and then we're going to
  152. 5:22hit create pass. So once we've created
  153. 5:25the pass, it should be noted right here.
  154. 5:28But the thing is is that we've created
  155. 5:29the pass, but there's no way for us to
  156. 5:32actually buy it. So what we have to do
  157. 5:34is click on this and then there should
  158. 5:37be a section here that says sales. And
  159. 5:40so now what we can do is turn on item
  160. 5:43for sale. And we can put whatever price
  161. 5:45we want in here for the player to
  162. 5:46purchase. The thing about the Robux
  163. 5:48amount is that the creator gets 70% of
  164. 5:52however much the price of this game pass
  165. 5:54is. So if let's say I priced it at 100
  166. 5:57Robux, then the creator gets 70 Robux
  167. 5:59out of that 100 Robux. So you can price
  168. 6:02this to be whatever you want. I can just
  169. 6:03price it to be 100 just to keep it
  170. 6:05simple. So we'll hit save changes. All
  171. 6:07right. And we have now done that. But
  172. 6:09here's another thing. If we create a
  173. 6:10game pass, then we should automatically
  174. 6:12have this in our inventory. So, we don't
  175. 6:14need to buy this game pass uh within the
  176. 6:17game. But for testing purposes, we might
  177. 6:19want to try and buy this game pass. So,
  178. 6:22we need to get rid of this game pass
  179. 6:23from our inventory temporarily so that
  180. 6:25we can buy it in studio to test it.
  181. 6:27Okay. So, I'm back on the Roblox page.
  182. 6:29We're going to go to inventory. And then
  183. 6:31what we're going to do is go to passes
  184. 6:34down here. and you should be able to
  185. 6:37find the path that you just created,
  186. 6:39test one, and let's click on this. So,
  187. 6:42what we're going to do is go on the top
  188. 6:43right. We're going to hit delete from
  189. 6:45inventory. So, once we do this, then we
  190. 6:47should be able to test by this uh in
  191. 6:50Roblox Studio. We also want to make sure
  192. 6:52we have the asset ID of this game pass
  193. 6:54saved. So, I'm going to click this
  194. 6:56button and click on copy asset ID. So,
  195. 6:59now this should be on our clipboard so
  196. 7:01that we can add this game pass into our
  197. 7:04Roblox game. Okay, we have our initial
  198. 7:06setup done. Now, let's get to scripting
  199. 7:08this game pass. So, what we're going to
  200. 7:09do is make a script in server script
  201. 7:12service really quick. So, we're just
  202. 7:13going to do this. Uh, we're going to
  203. 7:15delete these lines here. Okay. So, in
  204. 7:17order to manage anything related to game
  205. 7:19passes, we need to use a special service
  206. 7:22for this. Now, there are two services
  207. 7:24within the Roblox developer realm that
  208. 7:26people that people do get confused over.
  209. 7:29So there's this service called game pass
  210. 7:32service and there's another service
  211. 7:34called marketplace service. So you might
  212. 7:37ask which one of these two services do
  213. 7:39we use since both of them sound like
  214. 7:41they could work with handling game
  215. 7:43passes. I'm going to say this right now.
  216. 7:45You should not use game pass service
  217. 7:47because not only is it a deprecated
  218. 7:49feature but also marketplace service has
  219. 7:52everything that game pass service does
  220. 7:54but in a more modern and safe way. So
  221. 7:57this is what game pass service would
  222. 7:58look like. So we would say local game
  223. 8:01pass service equals game colon get
  224. 8:04service game pass service. So we do not
  225. 8:09want to use this. In the past I have
  226. 8:11used game pass service and and this has
  227. 8:13now been superseded by marketplace
  228. 8:16service. So this is what it's going to
  229. 8:17look like. Instead of game pass service
  230. 8:19we're going to say marketplace service.
  231. 8:23And we're basically going to do the same
  232. 8:24thing here with marketplace service. All
  233. 8:28right. All right. So, now that we know
  234. 8:29to use marketplace service, let's also
  235. 8:31make our game pass ID. So, we're going
  236. 8:33to say local game pass ID equals. And
  237. 8:37then we're going to paste our ID for the
  238. 8:40game pass we just created. So, it should
  239. 8:41look something like this. This script is
  240. 8:43going to be used to check whether the
  241. 8:45player has a current game pass or not.
  242. 8:47But for right now, what we're interested
  243. 8:49in is prompting the user to buy the game
  244. 8:52pass. And the way we do this is actually
  245. 8:54by using a local script instead of a
  246. 8:57script because we want to be able to
  247. 8:58display it on the player screen for them
  248. 9:00to be able to click it and then send it
  249. 9:02over to the server. So we're also going
  250. 9:04to create a local script probably in
  251. 9:06starter character scripts just to test
  252. 9:08this out. So we're going to hit the plus
  253. 9:10sign include a local script and we're
  254. 9:12basically just going to copy the same
  255. 9:14code that we had here. So we're going to
  256. 9:16copy this and then delete this, paste it
  257. 9:18into here. Okay. Okay. And so now what
  258. 9:20we're going to do is get our local
  259. 9:22player. We're we're just going to say
  260. 9:24local player equals game.players.local
  261. 9:28player. So now let's prompt the player
  262. 9:30to buy the game pass. What we're going
  263. 9:32to do is simply just say marketplace
  264. 9:35service colon prompt game pass purchase.
  265. 9:41And this takes in two arguments. The
  266. 9:43first one is going to be the player
  267. 9:45instance. Now, I now this is another
  268. 9:47thing people get tripped up about is
  269. 9:49whether they should pass in the player
  270. 9:51object itself or the player's user ID.
  271. 9:54We're just going to be passing in the
  272. 9:56player, which is our local player. Since
  273. 9:58we're using a local script and so now
  274. 10:00the second argument is going to be the
  275. 10:02game pass ID, which is going to be right
  276. 10:04here, contained in this variable called
  277. 10:06game pass ID. So, we're just going to
  278. 10:07pass in game pass ID. So, this is
  279. 10:10essentially how you prompt a game pass
  280. 10:12purchase to the player. If we go into
  281. 10:14the game, hit test, and hit play, then
  282. 10:16we should be able to see that as soon as
  283. 10:17we join into the game, Roblox should
  284. 10:20send us a prompt to buy the game pass
  285. 10:22that we just created. All right, so it
  286. 10:24says, "Would you like to buy test one
  287. 10:26for 100 Robux?" Now, thankfully in
  288. 10:28Roblox Studio, it allows us to test the
  289. 10:31purchase. So, we don't have to actually
  290. 10:33spend 100 Robux to buy this item. So, we
  291. 10:36could just simply hit this and we should
  292. 10:37be able to buy this just normally. So,
  293. 10:39it says it's been successful, but it
  294. 10:41doesn't do anything right now because we
  295. 10:43didn't tell the server to do anything
  296. 10:45once we bought this thing. So, that's
  297. 10:46what we're going to do right now. And
  298. 10:48what we're going to do is set up an
  299. 10:50event for marketplace service anytime
  300. 10:53that a game pass purchase has been made.
  301. 10:55And what we're going to do is say
  302. 10:56marketplace service
  303. 11:00prompt gamepass purchase finished. Oh
  304. 11:04jeez, that is a long name. Okay. Okay.
  305. 11:06And then we're going to connect this to
  306. 11:07a function. And this passes back three
  307. 11:10parameters. So the first one is the
  308. 11:13player instance. The second one is the
  309. 11:15ID that was passed through. And then
  310. 11:17finally a boolean to tell us whether
  311. 11:19this purchase was successful or not. So
  312. 11:21we'll just say uh purchase successful.
  313. 11:24So we're going to be using these three
  314. 11:27arguments to tell us which player bought
  315. 11:29what game pass and if it was successful
  316. 11:31or not. So down here, what we're going
  317. 11:33to do is make is make an if statement by
  318. 11:35saying if purchase successful and ID. So
  319. 11:41this ID right here is set equal to our
  320. 11:44game pass ID uh for test one. If this is
  321. 11:48equal to game pass ID, then what we're
  322. 11:50going to do is just simply print out
  323. 11:52that um let's say player.name and then
  324. 11:55we're going to concatenate this by
  325. 11:56saying has bought a game pass. Okay, so
  326. 12:01now we've told the server that uh if a
  327. 12:03game pass purchase has been has been
  328. 12:04made, then we're going to print to the
  329. 12:06output saying that this player has
  330. 12:07bought a game pass. Oo, I don't know how
  331. 12:09I made this mistake, but this should not
  332. 12:12be in the local script. This should be
  333. 12:14in the regular script up here. My
  334. 12:15apologies for getting confused on that,
  335. 12:17but it should be working now. You don't
  336. 12:18want to make that mistake. I'm telling
  337. 12:20you that right now. Okay, so we're going
  338. 12:22to buy test one. And what should happen
  339. 12:23is that as soon as it's done, then it
  340. 12:25should print down here that that Brawl
  341. 12:27Battle has bought a game pass. So, it
  342. 12:29should be working basically as intended.
  343. 12:31And so, that is how we can check if a
  344. 12:33specific player has bought a specific
  345. 12:35game pass. What we're about to do now is
  346. 12:37check if the player owns a game pass if
  347. 12:39we join to the game. But before we do
  348. 12:42that, I want to address some things. So,
  349. 12:44I'm currently in the games page of the
  350. 12:46game that we're working with. And
  351. 12:48in-game purchases for game passes isn't
  352. 12:50the only way for you to buy game passes
  353. 12:52because you can also buy game passes
  354. 12:54within the games page of the game that
  355. 12:57you're playing. going down here into the
  356. 12:59store tab. So, if we click this, we can
  357. 13:01actually see all of the game passes that
  358. 13:03are available to buy. If you buy one of
  359. 13:06these game passes, then you can join
  360. 13:08into the game and the the game can check
  361. 13:10if the player has this game pass without
  362. 13:13having them buy the game pass in the
  363. 13:16game. I want you to be able to
  364. 13:17understand this and know that there's
  365. 13:19two ways of of players buying game
  366. 13:22passes. It can either be through the
  367. 13:23games page or it can be in the game
  368. 13:25directly. And you need to be able to
  369. 13:27handle both of these cases if that does
  370. 13:29end up happening. All right, so we're
  371. 13:31back into the game. What we want to do
  372. 13:33now is check if the player already owns
  373. 13:35a game pass when they join into the
  374. 13:37game. So let's go back to our script and
  375. 13:40on top of here, we're going to make a
  376. 13:42player added event. So we're going to
  377. 13:44say game.players.player
  378. 13:46added connect function open close
  379. 13:49parenthesis pass in the player. Enter.
  380. 13:52What we're going to do is check whether
  381. 13:54the player owns a specific game pass.
  382. 13:56And here's how we're going to do it.
  383. 13:57We're going to say local has game pass
  384. 14:01equals marketplace service
  385. 14:05colon user owns game pass async. And
  386. 14:10this takes in two arguments. So you
  387. 14:12might have noticed that the first
  388. 14:14argument says user ID. It does not say
  389. 14:17the player object. But this is
  390. 14:19specifically saying that it wants the
  391. 14:21player's user ID. So that's what we're
  392. 14:23going to do. We're going to pass in the
  393. 14:24player user ID. And then the second
  394. 14:27argument is just going to be the game
  395. 14:28pass ID, which was up here. So we're
  396. 14:31just going to pass in game pass ID. So
  397. 14:34this should return a boolean of whether
  398. 14:36the player owns this game pass or not.
  399. 14:37So let's check if the player does have
  400. 14:40the game pass. Then we we could just
  401. 14:43check this by saying print uh
  402. 14:45player.name name uh concatenate this
  403. 14:48with a string by saying has a game pass
  404. 14:52upon joining.
  405. 14:54And there we go. That's this is a really
  406. 14:57basic way for us to test whether the
  407. 14:58player has a game pass if they join into
  408. 15:01the game. Uh, if we join into this game
  409. 15:03right now, um, I'm pretty sure this is
  410. 15:05not going to fire because we currently
  411. 15:07don't have this item in our inventory.
  412. 15:09And buying this through Roblox Studio
  413. 15:12does not count as adding this into our
  414. 15:15inventory. So, if we buy this game pass,
  415. 15:17then nothing should really change here.
  416. 15:20Uh, I I definitely don't see in the
  417. 15:23output that I own this game pass because
  418. 15:25I'm going to have to actually go into
  419. 15:26the game to buy this. So, let's check.
  420. 15:28If we don't have the game pass, then it
  421. 15:31should be able to display um then it
  422. 15:34should be able to display it properly in
  423. 15:35the output. So it should say that brawl
  424. 15:38battle has a game pass upon joining. But
  425. 15:40in reality we don't because we uh got
  426. 15:43rid of it from our inventory. Okay, so
  427. 15:45this has basically been taken care of.
  428. 15:46But the thing is if we have a function
  429. 15:49that returns something, we don't want to
  430. 15:51just call this one time and expect a
  431. 15:53guaranteed response because things can
  432. 15:56always go wrong with the network. And so
  433. 15:58we don't want to rely on this happening
  434. 15:59only once and something could definitely
  435. 16:01go wrong and we want to be able to
  436. 16:03handle it accordingly which is why we
  437. 16:05want to wrap this in a pall. So if you
  438. 16:07remember how palls are structured let's
  439. 16:09just comment this out really quick uh
  440. 16:11and drop a line down here. What we're
  441. 16:13going to do is say local success,
  442. 16:16error message equals pall function open
  443. 16:20and close parenthesis enter. And so
  444. 16:22we're basically just going to take our
  445. 16:24user owns game pass async um method and
  446. 16:27just paste it down here. So this is a
  447. 16:30safer way of knowing whether the player
  448. 16:32has a game pass or not. So instead of
  449. 16:34saying down here if has game pass, let's
  450. 16:36actually comment these out and let's uh
  451. 16:39indent this properly. What we can do
  452. 16:41instead is just simply check if this was
  453. 16:43not successful. So if not success then
  454. 16:48uh we'll write in an error message in
  455. 16:50we'll write an error message into the
  456. 16:52output. So instead of saying print we'll
  457. 16:54just simply put an error here and we're
  458. 16:56going to pass in our error message. Uh
  459. 16:59you can use an error or you can use a
  460. 17:01print statement. It doesn't really
  461. 17:02matter which one you use uh as long as
  462. 17:04you can see it in the output. Basically
  463. 17:07the difference here is that if we use an
  464. 17:08error message it's going to print it in
  465. 17:10red instead of white. So that's the only
  466. 17:13difference. So yeah, now that we've
  467. 17:14checked this, if this was not
  468. 17:15successful, then then we're going to
  469. 17:16print the error message. And we can also
  470. 17:18return this too, so that we don't want
  471. 17:20this to do any other weird things down
  472. 17:22here uh if it doesn't go well. Oh, and
  473. 17:25there's one thing we forgot to do, and
  474. 17:26that is incorporate the has game pass
  475. 17:28boolean. The reason we need to do this
  476. 17:30is because this can be successful, but
  477. 17:34it could say that the player does not
  478. 17:36have the game pass or the player does
  479. 17:37have the game pass, which is why we need
  480. 17:39to have the success variable, but also
  481. 17:41have a has game pass variable at the
  482. 17:44same time so that we can make the script
  483. 17:45do what it needs to do if the player
  484. 17:47actually does have the game pass. So,
  485. 17:49we're just going to drop a line down
  486. 17:50here. Say local has game pass equals
  487. 17:53false. And let's throw it down here by
  488. 17:56saying has game pass equals whatever
  489. 18:00this is going to give back to us. And so
  490. 18:02if this was not successful then throw an
  491. 18:04error message. And we can say down here
  492. 18:07again if has game pass then do whatever
  493. 18:10we we need to do down here. So we
  494. 18:11actually did need this all along. So
  495. 18:13this is the secure way of uh adding
  496. 18:16palls to our game passes when we
  497. 18:19implement them inside of our scripts.
  498. 18:21All right. Now, we're about to do
  499. 18:22something interesting, which is uh
  500. 18:25giving the player a tool if they own a
  501. 18:27certain game pass. Whether they join
  502. 18:29into the game after buying a game pass
  503. 18:31or if they have bought the game pass in
  504. 18:33the game, we want to be able to give
  505. 18:35this tool to the player and keep it on
  506. 18:38them even if they reset their character.
  507. 18:40So, what tool are we going to use? Um,
  508. 18:42we can basically just go to the toolbox
  509. 18:44and find whatever tool that we're going
  510. 18:45to use. Uh, maybe we can use that
  511. 18:47diamond sword that I showed you in the
  512. 18:48beginning in the beginning of the video.
  513. 18:50Uh, so let's just go to models and
  514. 18:52search up sword. Uh, and I think it
  515. 18:55should be right here. Yeah, Minecraft
  516. 18:57diamond sword. Let's just take this. Hit
  517. 18:59okay. So, we're going to take our
  518. 19:02Minecraft diamond sword. We're going to
  519. 19:03move this inside of server storage so
  520. 19:05that we can uh use this to put it inside
  521. 19:08of the player's backpack uh if they do
  522. 19:11own the game pass. Uh, we're also going
  523. 19:12to rename this to uh let's just say
  524. 19:15diamond sword with no spaces just to
  525. 19:17make it simple. Okay, so now that we
  526. 19:19have that taken care of, let's go back
  527. 19:21to our script. And what we want to do
  528. 19:24first is check if the player has
  529. 19:27successfully bought this game pass so
  530. 19:28that we can actually give the tool to
  531. 19:31the player uh once they buy the game
  532. 19:34pass. So first thing we're going to do
  533. 19:36is locate our diamond sword. We're going
  534. 19:37to say local sword equals game.server
  535. 19:41server storage
  536. 19:44colon find first child open and close
  537. 19:47parenthesis diamond sword. And if the
  538. 19:50sword does exist, because there's a
  539. 19:53chance that it might not, then we're
  540. 19:54going to uh drop a line down here. And
  541. 19:56then we're going to create a clone of
  542. 19:58the sword and then put it inside of the
  543. 20:00player's backpack. So, what we're going
  544. 20:02to do is say local cloned sword equals
  545. 20:06sword colon clone open and close
  546. 20:07parenthesis. And then we're going to set
  547. 20:09the parent of the cloned sword.
  548. 20:12Equals uh our player backpack. Okay, so
  549. 20:17now we're going to be able to give the
  550. 20:18player this sword into their backpack
  551. 20:20once they buy the game pass. However,
  552. 20:22we're not done here because let me show
  553. 20:24you what happens if we buy this game
  554. 20:26pass right now. If we decide to buy test
  555. 20:29one right now, then we hit okay. What
  556. 20:31should happen is in the output it says
  557. 20:33our diamond sword is in our backpack.
  558. 20:35Sweet. But what happens if we reset our
  559. 20:37character? If we reset our character,
  560. 20:40then our item is gone. We can't use it
  561. 20:43anymore. Where did our item go? If if
  562. 20:46tools are in a player's backpack, that
  563. 20:48doesn't mean that it's going to stay in
  564. 20:50the player's backpack. We have to use
  565. 20:52what's known as starter gear. If you
  566. 20:55remember from my tools video way back
  567. 20:56earlier in the series, um we use starter
  568. 20:59gear to basically say that if whatever
  569. 21:02tools in here, it's going to be cloned
  570. 21:04into the player's backpack every single
  571. 21:06time they reset their character. So, not
  572. 21:08only do we have to add the So, not only
  573. 21:11do we have to add the sword to the
  574. 21:13player's backpack, but we also have to
  575. 21:14add it to the player's starter gear as
  576. 21:16well, so that it'll save uh whenever the
  577. 21:19player resets their character. So,
  578. 21:21here's what we're going to do. We're
  579. 21:22first going to check if the player does
  580. 21:24not have this sword inside of starter
  581. 21:26gear. And then if it if they don't, then
  582. 21:28we're going to add this to their starter
  583. 21:29gear. So we're going to make a simple if
  584. 21:31statement. We're going to say if not
  585. 21:34player
  586. 21:36startergeear
  587. 21:38colon find first child. And we're not
  588. 21:41trying to look for this sword instance.
  589. 21:43We're trying to look for uh a name of
  590. 21:46the sword that resembles it. So we're
  591. 21:48just going to say sword.name.
  592. 21:50So, if you were to imagine this, we have
  593. 21:52our starter gear and we open it up. We
  594. 21:54want to see if there is a tool that's
  595. 21:57called the sword, which is the diamond
  596. 21:59sword. So, if they don't have it, so
  597. 22:01then what we're going to do is make
  598. 22:03another sword. We're going to clone it
  599. 22:05again and then put it inside of the
  600. 22:06player starter gear. So, we can just
  601. 22:08copy this code right here and then paste
  602. 22:10it in here. But this time, we're going
  603. 22:12to set the parent of this to be starter
  604. 22:15gear. So now this should work if we join
  605. 22:18into the game, buy the game pass, and
  606. 22:20then reset our character. We should be
  607. 22:23able to keep it once we reset our
  608. 22:24character. So let's buy the game pass.
  609. 22:27Let's hit okay. Not only will this be
  610. 22:29added to our backpack, but this will
  611. 22:31also be added to our starter gear uh as
  612. 22:33well. And if we reset our character,
  613. 22:36then what should happen is once we go
  614. 22:37back in, then we should still have our
  615. 22:39diamond sword in our backpack. Okay, but
  616. 22:43this was dealt only if the player bought
  617. 22:45the game pass in the game. But we also
  618. 22:47want to check if the player who
  619. 22:50previously bought this game pass before
  620. 22:51joining into the game in the stores page
  621. 22:53like I like I showed you earlier uh
  622. 22:55joins into the game and checks whether
  623. 22:57the player has the game pass or not. We
  624. 22:58want to do the same thing up here that
  625. 23:00we did down here except this is going to
  626. 23:02be if the player joins into the game for
  627. 23:04the first time. And we basically have
  628. 23:06the initial setup here done already. If
  629. 23:08the player does have this game pass then
  630. 23:09they have this game pass. So what we can
  631. 23:11do down here is just simply copy what we
  632. 23:14already had down here and just paste it
  633. 23:16into here. So it pretty much does the
  634. 23:19exact same thing as it did before. But
  635. 23:21this is a lot of copied code. So what we
  636. 23:23could do is create a function that helps
  637. 23:25us with this. Uh we could just say local
  638. 23:28function
  639. 23:30give sword open and close parenthesis
  640. 23:32enter. And all we need to do is just
  641. 23:34pass in the player in this function. So
  642. 23:37we could just copy this. So, we could
  643. 23:40just cut this, paste it into here. Uh,
  644. 23:42and then we could just call give sword
  645. 23:44by passing in the player argument. So,
  646. 23:47we could just pass in the player here.
  647. 23:49And then we can also just copy this and
  648. 23:51pass it into here as well. Uh, give
  649. 23:54sword, pass in the player. All right.
  650. 23:56And there we go. This is how we give a
  651. 23:58tool to a player if they own a game pass
  652. 24:01or if or do anything for that matter if
  653. 24:03a player does own a game pass. So, I'm
  654. 24:05glad I was able to show you a practical
  655. 24:07use case of using a game pass. So for
  656. 24:09this last part of the video, I want to
  657. 24:11show you how we can add data stores to
  658. 24:14store purchase history information of
  659. 24:16the player if they decide to buy game
  660. 24:18passes within the game. So let's say I
  661. 24:20did buy the game pass in the game. Um
  662. 24:23what if we wanted a way to store that
  663. 24:25information so that we can retrieve it
  664. 24:27back um to let us know that oh yeah,
  665. 24:30this player did buy a certain game pass
  666. 24:33uh during this specific time. We can do
  667. 24:34that using data stores. And I just find
  668. 24:37this to be very helpful if let's say a
  669. 24:39player decides to buy a game pass, but
  670. 24:40then there were some issues with
  671. 24:42granting whatever privileges the game
  672. 24:44pass was supposed to give to the player,
  673. 24:45but it just ended up not working. So
  674. 24:47then that player decides to go to the
  675. 24:49creator being like, "Hey, the game pass
  676. 24:51does not work. Do you think you can give
  677. 24:52me a refund or maybe check this out and
  678. 24:54see whether um you can fix this in your
  679. 24:57game?" One way for you to tell if this
  680. 24:59player does have the game pass is by
  681. 25:01looking at their purchase history data
  682. 25:03store. So, that's essentially what I'm
  683. 25:04going to be showing you how to do uh for
  684. 25:06this last part. Now, things will get a
  685. 25:08little complicated and there is one
  686. 25:10caveat to this is that this will not
  687. 25:12work if the player bought the game pass
  688. 25:15on the games page before joining into
  689. 25:17the game. Now, it now it could work, but
  690. 25:20it just adds more complication to the
  691. 25:22whole thing. You're going to have to
  692. 25:24check if the player has bought this for
  693. 25:25the first time when they join into the
  694. 25:26game and then do all these other sorts
  695. 25:28of things with data store switching.
  696. 25:29It's it gets pretty complicated. So, so
  697. 25:32what I'm going to show you is how to
  698. 25:33store data of a purchase transaction if
  699. 25:36a player buys a game pass in the game.
  700. 25:38So, what we're going to do is go to our
  701. 25:40script and at the very top we're going
  702. 25:42to get access to our data store service,
  703. 25:45which we're just going to say local data
  704. 25:47store service equals game get service
  705. 25:51data store service. And we want to use a
  706. 25:54data store to store all this
  707. 25:55information. Uh we can call this uh
  708. 25:58purchase history. And we're going to set
  709. 26:00this equal to data store service colon
  710. 26:06get data store. We're just going to be
  711. 26:08using a normal data store. We're not
  712. 26:10going to be using an order data store or
  713. 26:11anything like that. Uh and this is just
  714. 26:13simply going to be called purchase
  715. 26:15history. Okay. Now I want you to
  716. 26:17understand how this purchase history
  717. 26:19data store will be structured. I want
  718. 26:21you to imagine it like this. If, let's
  719. 26:23say, the player decided to buy uh the
  720. 26:25game pass, then we want to process
  721. 26:28information about that game pass
  722. 26:30purchase to to have it be sent to our
  723. 26:33purchase history. So, let's say we
  724. 26:34wanted to have information about um when
  725. 26:36the purchase was made, uh what the what
  726. 26:39the game pass name is, how much it costs
  727. 26:42in Robux, and just things like that. We
  728. 26:45want to store all that information in a
  729. 26:46table and then have that as one value
  730. 26:49inside of the data store. So, I want you
  731. 26:51to imagine this as if it was a table
  732. 26:53full of tables uh with different
  733. 26:56transactions and different purchase
  734. 26:58histories within this one data store. I
  735. 27:00think it'll make more sense once I show
  736. 27:02you what this looks like when we add
  737. 27:03this in. But essentially, what we're
  738. 27:04going to do is go down to our script and
  739. 27:08this is going to happen if we buy the
  740. 27:10game pass within the game. What we're
  741. 27:12going to do is drop two lines and I'm
  742. 27:13just going to make some comments to
  743. 27:15expand our understanding of what we're
  744. 27:16doing here. So, the first thing we're
  745. 27:18going to do is create our receipt. Uh,
  746. 27:22basically our table full of information
  747. 27:23based on the item that we just bought.
  748. 27:25The the second thing we're going to do
  749. 27:27is get a player's purchase history data
  750. 27:32so that we can take the player's already
  751. 27:34existing purchase history and add our
  752. 27:36receipt onto it. And then finally, we're
  753. 27:38going to add our receipt to the purchase
  754. 27:43history data. So, this is how it's going
  755. 27:46to be broken down. And now we're going
  756. 27:47to And now we're going to go through
  757. 27:49each step. So, we're first going to
  758. 27:51create our receipt, and this is going to
  759. 27:53be a table essentially. So, it's going
  760. 27:56to be a table full of information that
  761. 27:57we might want to see if a player decides
  762. 28:00to buy a game pass. So, right now, I'm
  763. 28:02thinking of four things we could
  764. 28:03potentially add into here. So the first
  765. 28:05one would be the name. The second one
  766. 28:07would be the ID. The third one would be
  767. 28:10the date. And the fourth one would be
  768. 28:13the price of that game pass. So we would
  769. 28:15just say price down here. And as you
  770. 28:17know, this is how we structure our
  771. 28:19tables. It's separated by commas or
  772. 28:21semicolons if you choose to do that as
  773. 28:23well. But I'm just going to do commas.
  774. 28:24And these are all going to be set equal
  775. 28:27to a certain value. So the name in this
  776. 28:29case, we're just going to call this
  777. 28:31diamond sword. And for the ID, we're
  778. 28:34going to set this equal to uh the ID
  779. 28:37that was passed into here when we bought
  780. 28:39the game pass. And then we're going to
  781. 28:40skip date for right now. But for but for
  782. 28:43price, we're just going to say 100
  783. 28:44because that's how much the game pass
  784. 28:46was. And for this date, now this might
  785. 28:48be a little confusing because I never
  786. 28:50taught you how time is displayed in
  787. 28:53inside of Roblox. But I just want you to
  788. 28:55follow what I do for right now. So what
  789. 28:57we're going to do is set this equal to
  790. 28:58OS time open and close parenthesis.
  791. 29:01We're going to use quotations and then
  792. 29:03say percentage sign lowercase X. Don't
  793. 29:06worry about what this means right now.
  794. 29:07We're going to I'm going to go over this
  795. 29:08in a future video, but this essentially
  796. 29:10gives us the date of when the player has
  797. 29:13bought this game pass. So, we now have a
  798. 29:15receipt. What we need to do now is check
  799. 29:17is get the player's purchase history
  800. 29:19that's already existed. We're going to
  801. 29:21say local success data equals pall
  802. 29:26function open close parenthesis enter.
  803. 29:28We're going to return um purchase
  804. 29:32history colon get async because that's
  805. 29:35what we're going to try and retrieve and
  806. 29:38store it into data. We're simply just
  807. 29:40going to pass in the string of player
  808. 29:43user user ID. And so let's check if this
  809. 29:46was not successful. So, if this was not
  810. 29:49successful, then what we're going to do
  811. 29:50is throw in an error message saying that
  812. 29:53uh we failed to fetch purchase history.
  813. 29:58And we're also just going to return this
  814. 29:59because we don't want to add this to our
  815. 30:02because we don't want to add this to our
  816. 30:03data store if we were not able to
  817. 30:05retrieve the data store in the first
  818. 30:06place. Okay. But let's say if the data
  819. 30:08did fail, let's say if the player
  820. 30:11doesn't have any data to begin with,
  821. 30:14then what we're going to do is we're
  822. 30:15basically just going to set data to an
  823. 30:17empty table. So we're just going to say
  824. 30:19if data equals nil, then we're going to
  825. 30:23set data equal to an empty table. The
  826. 30:26reason again we are doing this is
  827. 30:28because the player could pot this could
  828. 30:30potentially be the first purchase that
  829. 30:31the player has ever done. And if it is
  830. 30:33the case, then we're going to set data
  831. 30:35equal to an empty table so that we can
  832. 30:37add our receipt to the table and then
  833. 30:39set that to the player purchase history.
  834. 30:41Okay. And so now we can add our receipt
  835. 30:44to our data table. So we're just simply
  836. 30:46going to use the table function called
  837. 30:48table.insert
  838. 30:50open and close parenthesis. So in our
  839. 30:53data table, we're going to add our
  840. 30:56receipt table that was up here. So,
  841. 30:58we're basically taking this receipt
  842. 31:00transaction and put it inside of our uh
  843. 31:02data table so that we can take this data
  844. 31:04table and set it to uh the player's
  845. 31:07transaction history. And so now down
  846. 31:10here, what we're going to do is say
  847. 31:11local success,
  848. 31:14error message just in case it does fail.
  849. 31:16We're going to set this equal to pall
  850. 31:18function open close parenthesis enter.
  851. 31:21We're going to simply say purchase
  852. 31:24history colon set async open and close
  853. 31:28parenthesis player user ID and then
  854. 31:32we're going to pass in our data table.
  855. 31:35And finally, let's do one more check to
  856. 31:37see if this was not successful. If not
  857. 31:40success, then error. And we're going to
  858. 31:43pass in our error message that we have
  859. 31:46up here. Okay, this is our entire script
  860. 31:48right here. I'm going to show you what
  861. 31:50this looks like within the game and then
  862. 31:52we're going to do one quick recap of
  863. 31:54everything that we coded up until this
  864. 31:56point. Okay. Now, one quick thing we can
  865. 31:57do is print out our results in the
  866. 32:00output so that we can see uh our data in
  867. 32:03our purchase history for the specific
  868. 32:04player. Uh, so what we're going to do is
  869. 32:06just simply say up here with our player
  870. 32:08added event is go down here and say
  871. 32:11local data equals purchase history colon
  872. 32:16get async and then pass in the player
  873. 32:20user ID. Then what we're going to do is
  874. 32:22check if that data actually does exist.
  875. 32:25Then we're going to loop through all the
  876. 32:27entries within each table. So we're
  877. 32:30going to say for i, receipt in i pairs
  878. 32:35open and close parenthesis data. And
  879. 32:37we're using i pairs because we want to
  880. 32:39go through each one sequentially. So
  881. 32:41we're going to say do and then we're
  882. 32:42going to use another for loop because as
  883. 32:44you know data is one big table that
  884. 32:46consists of multiple tables resembling
  885. 32:49each transaction. So what we're going to
  886. 32:51do is say for key that's what we're
  887. 32:53going to call it comma value in pairs
  888. 32:56and we're going to pass in our receipt
  889. 32:59table do print we're going to print out
  890. 33:02the key and the value. So this is
  891. 33:06essentially how we're going to print out
  892. 33:07all of our data that's in the purchase
  893. 33:09history so that we can see it in the
  894. 33:11output. So this is basically how uh our
  895. 33:14code is going to be structured. Okay. So
  896. 33:15there was actually a typo here with uh
  897. 33:18with our receipt table. So instead of os
  898. 33:21time, it's actually os. I got the the
  899. 33:24function messed up. Okay. So now up
  900. 33:26until this point, we should be able to
  901. 33:28see this work as expected. So if we join
  902. 33:30into the game, we should basically see
  903. 33:33nothing in the output because we didn't
  904. 33:34buy anything yet. But if we decide to
  905. 33:36buy this item right here, then what
  906. 33:38should happen is in the output, it
  907. 33:40should say Brawl Battle has bought a
  908. 33:42game pass, but nothing is being printed
  909. 33:43out right now. So if we stop the game
  910. 33:46and then join back into the game, what
  911. 33:48we should see now in the output is our
  912. 33:51purchase history uh being displayed. So
  913. 33:55as you can see for our first entry, it
  914. 33:58says our ID of the item, then it's going
  915. 34:00to say the date, which is formatted like
  916. 34:02this with OS.ATE, uh the name of the
  917. 34:05item, which is diamond sword, and then
  918. 34:06the price of 100. And you can do this
  919. 34:09again by buying this and then hitting
  920. 34:11okay. And then we should be able to
  921. 34:13leave the game and then join back again
  922. 34:16to see this happen uh in the output.
  923. 34:19Now, typically uh if this was an actual
  924. 34:21game, you should only be able to see
  925. 34:23this one time. So, ideally, this would
  926. 34:25be uh one this would be one game pass
  927. 34:28and then this would be a whole another
  928. 34:30game pass right here because it's not
  929. 34:32possible for you to buy the same game
  930. 34:34pass uh within a game unless you delete
  931. 34:36that item and put it back into the game.
  932. 34:39Okay, that was a lot to take in, but I
  933. 34:42really hope that this gave you insight
  934. 34:44into more of what you can do with game
  935. 34:46passes. Is saving game pass transactions
  936. 34:49necessary? I would say in some instances
  937. 34:51they are, but you can definitely get
  938. 34:54away with not doing this if you don't
  939. 34:55want to. But this is something I wanted
  940. 34:58to address in this video because I know
  941. 35:00that some people might find this
  942. 35:01helpful, especially if you're following
  943. 35:02along with this course. Uh, and I hope
  944. 35:05everything we've done in this in this
  945. 35:07and I hope everything we've done in this
  946. 35:09tutorial made sense to you. If you want
  947. 35:11to know more about how data stores work,
  948. 35:13since that's a very prevalent thing we
  949. 35:14used in this video, then I encourage you
  950. 35:16to watch my data stores video that I
  951. 35:18will have a link for you right here. But
  952. 35:21with that being said, I hope you found
  953. 35:22this video to be helpful and I will see
  954. 35:24you in the next episode. Take care.

About this transcript

This page contains the full transcript of Gamepasses (One-Time Robux Pass & DataStore Receipt) - Roblox Advanced Scripting #21 (2024) by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 7,248 words across 954 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.