YouTube2Text

Scripting the Pet Inventory Gui! Roblox Studio Simulator Guide Episode 27 — Transcript

by MonzterDEV · 14,276 words · 1,893 segments · language en · Watch on YouTube

Full transcript

  1. 0:00what's going on ladies and gentlemen in
  2. 0:00today's episode of the simulator series
  3. 0:02we're going to be scripting the pet
  4. 0:03inventory gui now as always if this
  5. 0:05video does help you guys out or you guys
  6. 0:07do enjoy it make sure you smash the like
  7. 0:08button also hit the subscribe button and
  8. 0:09turn this post notifications on if you
  9. 0:11want to get notified when upload more
  10. 0:12roblox vomit content additionally i have
  11. 0:14a patreon if you like to support me and
  12. 0:15gain access to all the scripts and the
  13. 0:17game file i make during this episode
  14. 0:18there's a link down below in description
  15. 0:19and you guys can go and check that out
  16. 0:20with that being said let's get into it
  17. 0:22hopping directly into eating simulator
  18. 0:23to showcase the features that we're
  19. 0:24going to be creating today as we can see
  20. 0:26that we have a button at the bottom left
  21. 0:27which says pets we've created this bun
  22. 0:29and we also created this gui in the last
  23. 0:31episode as well today we're going to be
  24. 0:32doing is scripting this bun to open and
  25. 0:34display this gui and we're going to be
  26. 0:36scripting this entire gui so inside of
  27. 0:38here this container frame is going to
  28. 0:39populate with all of the different pets
  29. 0:41that the player currently owns this
  30. 0:42little text label right here will
  31. 0:43display how many pets the player
  32. 0:45currently has equipped and this one will
  33. 0:46display how many pets the player
  34. 0:47currently has stored within their
  35. 0:48inventory if you click on a pet it will
  36. 0:50pop up inside a little info frame
  37. 0:52displaying the pet the rarity the stats
  38. 0:54and an unequip or any quit bun depending
  39. 0:56on if the player has one equipped or not
  40. 0:58if you already have the max amount of
  41. 0:59pets equipped and you try to look up a
  42. 1:00new one we will get a little warning
  43. 1:02text popping up at the top of the screen
  44. 1:03additionally you can unequip a pet or
  45. 1:05equip that and then you have the multi
  46. 1:06delete button right here as well which
  47. 1:08when we click this it will change the
  48. 1:09info frame right here to display this
  49. 1:11frame and then we can select all the
  50. 1:12pets that we want to delete this number
  51. 1:14will update right here as well as a
  52. 1:15check mark on the left of each of the
  53. 1:17pets and we can click confirm and all
  54. 1:18those pets will be deleted so with all
  55. 1:20that being said let's hop directly into
  56. 1:22studio and start working so the first
  57. 1:23thing we're going to do is go inside of
  58. 1:24the storage gy inside of the pet
  59. 1:26inventory and right here we have a
  60. 1:27script called button and we're gonna
  61. 1:29actually use this to script this pet bun
  62. 1:31right there so inside of the script we
  63. 1:33have the buttons gui which refers
  64. 1:34directly to this screen gui right here
  65. 1:36and inside of the screen gui we have the
  66. 1:38button holder which that is for the
  67. 1:39right hand side of the screen all of
  68. 1:41those buttons and the left button holder
  69. 1:42is obviously for the left hand side of
  70. 1:44the screen so where we create the
  71. 1:45settings button variable what we want to
  72. 1:47do is we want to say button gui dot left
  73. 1:49button holder dot pets and then we can
  74. 1:51rename settings button to pets button
  75. 1:53and we just copy this paste that
  76. 1:55directly right here so whenever we click
  77. 1:56on this button what we want to do is we
  78. 1:58want to enable or disable this screen
  79. 2:00gui right here which is the pet
  80. 2:02inventory so now we're done with that we
  81. 2:04have the bun all set up the next thing
  82. 2:05we're going to do is we're actually
  83. 2:06going to go inside of the replicated
  84. 2:07storage inside the config folder so
  85. 2:09inside of here we're gonna insert a new
  86. 2:10module script and we'll rename that to
  87. 2:12pets and inside of this table right here
  88. 2:14we're gonna list each of the individual
  89. 2:16pets so dog and we're gonna set them to
  90. 2:18a table with all the rarities so common
  91. 2:20and we're gonna set each of the rarities
  92. 2:22to the stats that the pet is gonna offer
  93. 2:24so for instance if we get a common dog
  94. 2:26pet the stats that this is gonna offer
  95. 2:28is gonna be 2.5 and if we get an
  96. 2:30uncommon dog pet then its stats are
  97. 2:32going to be 3.5 and if we get a rare dog
  98. 2:34pet then the stats are going to be 4.5
  99. 2:35let's make sure that we add commas to
  100. 2:37each of those and there we go currently
  101. 2:38our rarity system only goes up to rare
  102. 2:40so that's why we're just making comments
  103. 2:42now let's put a comma and we're going to
  104. 2:43do this for each of the individual pets
  105. 2:45so we have dog bunny cat we have a fox
  106. 2:48and now i'll actually start increasing
  107. 2:49the stats on this one as well so we'll
  108. 2:52just increase all those stats by
  109. 2:53basically one and then after fox we have
  110. 2:55the turtle and the pick so for the pig
  111. 2:58we'll once again increase all the stats
  112. 3:00by one as well it really doesn't matter
  113. 3:01considering this is just test data but
  114. 3:03i'm just showing you guys what you can
  115. 3:04do the next thing we're gonna do is
  116. 3:06we're gonna actually script giving a
  117. 3:07player to a pet so inside of the server
  118. 3:09script service inside of utils we have a
  119. 3:12rewards module which basically handles
  120. 3:14all the functions of how we reward
  121. 3:15players so what we're gonna do inside of
  122. 3:17here is we're going to create a new
  123. 3:18function and this is going to be rewards
  124. 3:20dot pet and this function is going to
  125. 3:22accept a player which of course is a
  126. 3:24player the name of the pet so dog fox or
  127. 3:26anything like that and we're just going
  128. 3:27to say that's pet and that's going to be
  129. 3:28a string and then finally we are going
  130. 3:30to accept rarity as a string as well now
  131. 3:32the way that we're gonna have our pet
  132. 3:33set up is each of the pets is going to
  133. 3:35be a folder stored with inside of the
  134. 3:37player now the folder name is gonna be a
  135. 3:39unique id and the reason that we need to
  136. 3:41have a unique id for every single pet is
  137. 3:44because let's say that the player has a
  138. 3:45hundred dollar all the dogs need to have
  139. 3:47a specific unique id otherwise we would
  140. 3:49never be able to tell any dog apart now
  141. 3:51this becomes more important when you
  142. 3:52have specific systems for individual
  143. 3:54pets such as if you had a level system
  144. 3:56for each individual pet if every single
  145. 3:58individual pet had their own level you
  146. 4:00would want to have a unique id attached
  147. 4:02to that pet so you can easily identify
  148. 4:04that specific pet and give it back the
  149. 4:05stats that it originally had now the way
  150. 4:07that we're gonna generate the unique id
  151. 4:09is by actually getting a service and the
  152. 4:11service that we're gonna require is the
  153. 4:13http service so we're going to create a
  154. 4:15variable for that and then inside of the
  155. 4:16function we're going to say local folder
  156. 4:18and we're going to create an
  157. 4:19instance.new folder and we're actually
  158. 4:21going to parent that to the
  159. 4:22player.pet inventory which we haven't
  160. 4:24created yet but we will create soon pet
  161. 4:26inventory is going to be a folder inside
  162. 4:28of the player very similar to how we
  163. 4:29have our leader stats or our other
  164. 4:31inventory systems as well and we're
  165. 4:32going to name the folder http service
  166. 4:34and we're going to use a method called
  167. 4:36generate guid which will generate the
  168. 4:38unique id for us and then inside of here
  169. 4:41we want to say false because we don't
  170. 4:42want the unique id to be wrapped in
  171. 4:44curly braces which we can see is the
  172. 4:46argument right here so now that we've
  173. 4:48created and name that folder the next
  174. 4:49thing we want to do is we want to create
  175. 4:50a string value for the pet rarity so
  176. 4:52we're going to say local pet rarity
  177. 4:54equals instance dot new string value and
  178. 4:57we're gonna parent this to the folder
  179. 4:59that we just created then we're gonna
  180. 5:00set the pet rarity.value to the rarity
  181. 5:03of the pet which is passed to us when we
  182. 5:04call this function and we also need to
  183. 5:06name this as well so we're gonna say pet
  184. 5:07rarity.name
  185. 5:09equals rarity and then we're gonna do
  186. 5:11this exact same thing for the type of
  187. 5:12the pet so we're gonna copy this we'll
  188. 5:14paste it and we'll rename this from pet
  189. 5:16rarity to pet id you could also say pet
  190. 5:19type but we're gonna go with pet id
  191. 5:21right here just to keep our system
  192. 5:22consistent throughout our entire project
  193. 5:24so pet id is gonna be a string value
  194. 5:26we're gonna parent that to the folder
  195. 5:27that we already created and now we need
  196. 5:28to change the rarity.name and the
  197. 5:30rarity.value so the name is going to be
  198. 5:32id and the value of this is actually
  199. 5:34going to be the pet that we once again
  200. 5:36passed through this function now finally
  201. 5:37we're going to create a bull value which
  202. 5:39is going to store if the pet is
  203. 5:40currently equipped or not so we're going
  204. 5:42to say local equipped equals instance
  205. 5:44dot new full value we're going to parent
  206. 5:46that to the folder we're going to set
  207. 5:48the name of this to equipped and we're
  208. 5:51going to set the value of this by
  209. 5:53default to false because the pet is of
  210. 5:55course going to be not equipped by
  211. 5:57default so whenever we reward a player a
  212. 5:59pet what this is going to do is it's
  213. 6:00going to create a brand new folder and
  214. 6:02it's going to store the folder inside of
  215. 6:03the player.pet inventory folder the name
  216. 6:05of this folder is gonna be a unique id
  217. 6:07so it's gonna be basically a bunch of
  218. 6:08random numbers and letters then inside
  219. 6:10of this folder that we just created
  220. 6:12there's going to be two string values
  221. 6:14and one full value one of the string
  222. 6:15values will be named rarity and that'll
  223. 6:17store the rarity of the pet the other
  224. 6:19string value will be named id and
  225. 6:21that'll actually store the type of the
  226. 6:23specific pet then we have the bull value
  227. 6:25which is going to be named equipped and
  228. 6:26by default it's going to be set to false
  229. 6:28but whenever we actually equip the pet
  230. 6:29it will be set to true now we need to
  231. 6:31actually create the data for the player
  232. 6:33so inside of our server script service
  233. 6:34we're going to go over to the player
  234. 6:36data inside of here let's scroll all the
  235. 6:38way down to right below this for loop
  236. 6:39and right above our success we're going
  237. 6:41to create the pet inventory folder so
  238. 6:42we're going to say local pet inventory
  239. 6:44equals instance dot new folder we're
  240. 6:47gonna parent that to the player the
  241. 6:48folder name is going to be pet inventory
  242. 6:52so now that we've created that folder we
  243. 6:53have to see if the player has any pets
  244. 6:55and if they do have any pets then we
  245. 6:56have to loop through all those pets and
  246. 6:58add them directly back to the player's
  247. 6:59folder so what we're gonna do is we're
  248. 7:00gonna say if return value dot pet
  249. 7:03inventory then so if the player has any
  250. 7:06pets what we're gonna do is we're gonna
  251. 7:07loop through the return value.pet
  252. 7:09inventory and now in this for loop the
  253. 7:11index is actually gonna be the uui date
  254. 7:13and the value is gonna be info in pairs
  255. 7:15return value dot pet inventory do now
  256. 7:18when we move through here what we're
  257. 7:19going to do is we're going to actually
  258. 7:20do the exact same thing that we did when
  259. 7:22we reward the pet to the player we can
  260. 7:24simply just copy all of the stuff that
  261. 7:26we do inside of here and paste it
  262. 7:27directly into here now we're not going
  263. 7:28to actually use the http service to
  264. 7:30generate a new unique id what we're
  265. 7:32gonna do is we're gonna set the folder
  266. 7:33name to the uuid which comes from right
  267. 7:35here inside of the loop then for the
  268. 7:37rarity this is gonna be stored within
  269. 7:38the info table so we're gonna say
  270. 7:40info.rarity for the pet id we're gonna
  271. 7:42say info.id and then for the equipped
  272. 7:44we're going to say info dot equip and
  273. 7:46there we go now this whole info table
  274. 7:48might be really confusing for you don't
  275. 7:49worry we're about to create this so
  276. 7:51you're going to see where the rarity
  277. 7:52comes from the id comes from and the
  278. 7:54equip comes from as well so now when we
  279. 7:55want to save the player's data that's
  280. 7:57when we're going to create the table so
  281. 7:58we're going to say local pet inventory
  282. 8:00equals a brand new table then we're
  283. 8:02going to do is we're going to loop
  284. 8:03through all the pets inside of the
  285. 8:05player's pet inventory folder so we're
  286. 8:07going to say for underscore pet in
  287. 8:08ipairs player.pet inventory get children
  288. 8:13do and now remember whenever we reward
  289. 8:14the player a pet we are going to create
  290. 8:16a new folder and put that inside of the
  291. 8:18pet inventory so now when we're saving
  292. 8:20we're going through that folder we're
  293. 8:22getting all the children which if the
  294. 8:23player does have any pets the children
  295. 8:25would be a folder with the name as the
  296. 8:27uuid and then that folder will add the
  297. 8:29string values and the bull value inside
  298. 8:31it as well with all the other
  299. 8:32information so what we're going to do is
  300. 8:33we're going to say pet inventory and
  301. 8:34we're going to add a brand new pet to
  302. 8:36this so we'll say pet.name which
  303. 8:38remember this is going to be the pet's
  304. 8:40unique id because the name of the folder
  305. 8:42is the uuid and we're going to set that
  306. 8:44equal to a brand new table inside of the
  307. 8:46table we're going to have an id field
  308. 8:47and we're going to set this to the
  309. 8:48pet.id which is the string value dot
  310. 8:51value so that we get the value of the
  311. 8:53string value then we're going to do this
  312. 8:54again but instead of for the id we're
  313. 8:56going to do this for the rarity so
  314. 8:58pet.rarity.value because remember it's a
  315. 9:00string value that's why we have to say
  316. 9:02dot value finally we're going to do this
  317. 9:03for equip as well so
  318. 9:06pet.equipped.value and now that we've
  319. 9:07added all the players pets to the pet
  320. 9:09inventory table what we want to do is we
  321. 9:11want to save that down here so we're
  322. 9:12going to save pet inventory make sure
  323. 9:14you capitalize the p equals the variable
  324. 9:16that we just created okay so that is
  325. 9:18perfect now we need to do is we need to
  326. 9:20actually reward the player the pet so a
  327. 9:22couple episodes ago we created this egg
  328. 9:24script inside of the server script
  329. 9:25service which handles hatching eggs
  330. 9:26inside of our function called hatch is
  331. 9:28where we determine what pet we're going
  332. 9:30to give to the player and now we need to
  333. 9:31actually reward that pet so at the top
  334. 9:33of our script we need to require the
  335. 9:34rewards module and first we need to get
  336. 9:36the server script service so we're going
  337. 9:38to say server script service and then we
  338. 9:40can just copy this x config because we
  339. 9:41already have part of this here and then
  340. 9:42we'll say server script service dot
  341. 9:44utils dot rewards there we go and then
  342. 9:46we're going to set the variable to
  343. 9:48rewards so now we have a rewards module
  344. 9:50and now inside of the hatch function
  345. 9:51right below where we actually choose the
  346. 9:53pet and create the pet variable we're
  347. 9:54gonna say rewards dot pet and we'll pass
  348. 9:57through the player the pet dot id and
  349. 9:59the pet dot rarity as well and now
  350. 10:01remember inside of her choose pet
  351. 10:02function this pet is actually a table
  352. 10:05from our pets config and you might be
  353. 10:06confused why this pet variable has an id
  354. 10:08and rarity but remember inside of the
  355. 10:10choose pet function we're actually using
  356. 10:12the eggs config and if you're confused
  357. 10:14about this eggs config we can look
  358. 10:15inside of here and inside of the eggs
  359. 10:16config we have the egg then it has a
  360. 10:18table called pets and inside of this
  361. 10:20array it has tables with id rarity and
  362. 10:22chance so that's how we're getting the
  363. 10:23id and the rarity and now we're actually
  364. 10:25rewarding the pet to the player and now
  365. 10:27we can actually test this out if we want
  366. 10:28to so let's go ahead and start per game
  367. 10:29so inside of our game we're going to
  368. 10:30hatch an egg and now we can see that
  369. 10:32we've received the common cat so let's
  370. 10:33look under players under monster we have
  371. 10:35the pet inventory folder right here and
  372. 10:36now we see we have a folder inside of
  373. 10:38here which is named after a unique id
  374. 10:40and inside of here we have a bull value
  375. 10:42which is called equipped we have a
  376. 10:43string value which is called id the id
  377. 10:45is set to cat which is the pet that we
  378. 10:46just got and the rarity is at the common
  379. 10:48and that's the rarity of the cat that we
  380. 10:50just got as well so now if we can
  381. 10:51actually again we can see a new photos
  382. 10:53created inside of our pet inventory with
  383. 10:54another unique id the equip is set to
  384. 10:56false the id is set to pig and the
  385. 10:58rarity is set to rare so we are actually
  386. 11:00now rewarding the player the pet which
  387. 11:01is awesome so now with all that being
  388. 11:03done we can actually start working on
  389. 11:04and scripting the gui so i'm going to go
  390. 11:06ahead and close all of the scripts that
  391. 11:07we currently have open and we'll close
  392. 11:09some of the folders and now let's
  393. 11:10actually go into the pet inventory
  394. 11:11screen gui let's open up the handler for
  395. 11:13starters we're actually going to delete
  396. 11:15pretty much everything out of here so
  397. 11:17we're just going to clear this all out
  398. 11:18and basically just make it a normal
  399. 11:20brand new module script so just like
  400. 11:21that and now we want to make some small
  401. 11:23adjustments to the gui so inside of the
  402. 11:24frame inside the container inside of
  403. 11:26that container inside of this template
  404. 11:28right here and inside of this holder we
  405. 11:30need to set the visibility of the delete
  406. 11:31text label to not visible so that we
  407. 11:33don't always see this and the same goes
  408. 11:35with the equip as well and then finally
  409. 11:36we also want to set the template to not
  410. 11:38visible as well then we can close all of
  411. 11:40these and we can go directly inside of
  412. 11:42our manager now within our manager we're
  413. 11:44going to clear some of these variables
  414. 11:45out because we're not going to need all
  415. 11:46this stuff so we'll leave the handler
  416. 11:48for now we'll keep the remotes we won't
  417. 11:49be using the settings but we will be
  418. 11:51using the pets config so from the
  419. 11:52replicated storage we're going to get
  420. 11:53the config.pets so now we have the pets
  421. 11:56config let's go ahead and rename this
  422. 11:57from settings to pets config we're also
  423. 11:59going to need the pet models as well so
  424. 12:01we're going to say local pet models
  425. 12:03equals
  426. 12:04replicatedstorage.pets then since these
  427. 12:06variables are already created we can
  428. 12:07actually keep the screen guy the frame
  429. 12:09and the container we can also keep the
  430. 12:10exit button as well and the template is
  431. 12:12good too but we're gonna delete the on
  432. 12:14and off color and then we're gonna
  433. 12:15delete the generate settings function
  434. 12:17and this for loop right here too so now
  435. 12:19if that's all properly cleaned up this
  436. 12:21is exactly what you should have left
  437. 12:22inside of your script all right so now
  438. 12:24what we're going to do is we want to
  439. 12:25create a for loop for generating the
  440. 12:27player's pets and how do we know what
  441. 12:28pets the player has well all the pets
  442. 12:30are stored inside of the folder named
  443. 12:32pet inventory inside the player so we're
  444. 12:33going to say for underscore pet in
  445. 12:35ipairs player.pet inventory get children
  446. 12:40do now let's create a function called
  447. 12:41pet instance to table and now this is
  448. 12:44going to accept an instance called pet
  449. 12:46inside of this function we're going to
  450. 12:47create a new variable called new pet and
  451. 12:49we're going to set that to a blank table
  452. 12:51and then using this table we're going to
  453. 12:52say
  454. 12:53newpet.uuid
  455. 12:55equalspet.name and now if you're
  456. 12:56confused by this how we're going to
  457. 12:57actually use this function is we're
  458. 12:59going to say local pet table equals pet
  459. 13:02instance 2 table and we're going to pass
  460. 13:04through the pet and remember inside of
  461. 13:05the pet inventory folder inside of the
  462. 13:07player when we loop through here this
  463. 13:08pet variable is going to be a folder and
  464. 13:10the name of that folder is going to be
  465. 13:12the unique id of that pet so that's why
  466. 13:14we're creating a brand new table and
  467. 13:15sending the uuid property of that table
  468. 13:17to the pet.name as that is what the uuid
  469. 13:20is then we're gonna say newpet.id which
  470. 13:23refers to the actual type of the pet
  471. 13:25such as dog frog pig or anything like
  472. 13:27that and how we're gonna get that is by
  473. 13:29saying pet dot id dot value because
  474. 13:32remember inside of the actual pets
  475. 13:34folder there is a string value called id
  476. 13:36and the value of that is the id and then
  477. 13:38we can duplicate that and then we're
  478. 13:39just going to do the same thing for the
  479. 13:40rarity so inside of the pet we have the
  480. 13:42rarity string value and we want to get
  481. 13:44the value of that and then we're going
  482. 13:45to say new pet dot equipped and that's
  483. 13:48also inside of the pet dot equipped dot
  484. 13:50value and the final thing we want to do
  485. 13:51is we want to return the table that we
  486. 13:53just created and now already inside this
  487. 13:55for loop we are setting a brand new
  488. 13:56variable to the table that we get
  489. 13:58returned from this function then what we
  490. 13:59want to do is above this function we're
  491. 14:01going to create a new function and the
  492. 14:02name of this function is going to be
  493. 14:04generate pet and it's going to accept
  494. 14:05the pet which is going to be a table and
  495. 14:07that's actually going to be the exact
  496. 14:09table that we create in this function
  497. 14:10right here so as we're going through
  498. 14:12this for loop and we get the brand new
  499. 14:13pet table we want to call the
  500. 14:15generatepet function and pass through
  501. 14:17the pet table that we just created now
  502. 14:18inside of the generatepet function what
  503. 14:20we're going to do is we're going to
  504. 14:21create a new variable called clone and
  505. 14:22we're going to set that to the template
  506. 14:24and we're going to clone that then we
  507. 14:25want to make sure that we set the
  508. 14:26visibility of it to true and we also
  509. 14:28need to make sure that we set the parent
  510. 14:30of this to the container frame then
  511. 14:33let's set the name of this to the pet
  512. 14:35dot uuid now let's go look at the
  513. 14:37template so we see we have the template
  514. 14:38right here we want to change the pet
  515. 14:39name we probably want to modify the
  516. 14:41equipped and we also want to modify the
  517. 14:43viewport frame as well so what we want
  518. 14:44to do is we want to say clone dot holder
  519. 14:46dot pet name dot text equals clone dot
  520. 14:50id and we use g sub on this because in
  521. 14:52case any of your pets have like a space
  522. 14:54in between there you're going to want to
  523. 14:55replace the underscore with an actual
  524. 14:57space and we also want to set the equip
  525. 14:59text label to either visible or not
  526. 15:01visible based on if the pet is actually
  527. 15:03equipped or not so we're going to say
  528. 15:04clone.holder.equipped.visible
  529. 15:07equals and then we're going to say pet
  530. 15:09dot equipped oh and i meant to say
  531. 15:11pet.id and then the g-sub not clone id
  532. 15:14because that doesn't make any sense now
  533. 15:15the reason that we're setting the
  534. 15:16visibility to pet.equipped is because if
  535. 15:18the pet is equipped this will be set to
  536. 15:20true otherwise it will be set to false
  537. 15:22so now that we have both of those things
  538. 15:24set the next thing we need to do is we
  539. 15:25need to work on the viewport frame now
  540. 15:27if you guys remember from a couple of
  541. 15:28episodes ago when we created the eggs
  542. 15:29billboard gui we actually worked with
  543. 15:31the viewport frame in there and we did
  544. 15:33that exact same thing so we can actually
  545. 15:34copy the code directly from this script
  546. 15:36and put it directly into our other
  547. 15:37script additionally i saw a comment on
  548. 15:39my last video which said that people are
  549. 15:40getting a red underscore when using the
  550. 15:42set primary part c frame and the reason
  551. 15:44for this is because i think literally
  552. 15:46after i uploaded my video they actually
  553. 15:48depreciated the set primary part c frame
  554. 15:51method and replaced it with the pivot 2
  555. 15:52method so if you guys were getting that
  556. 15:54error in the last episode i'm sorry
  557. 15:55about that it literally just happened as
  558. 15:57i upload it because you guys saw on my
  559. 15:59recording there were no issues there so
  560. 16:01that is really weird all you have to do
  561. 16:02is change that method from set primary
  562. 16:04part c frame to pivot 2 and it will be
  563. 16:06the exact same thing and it'll be all
  564. 16:07good with that all being said what we're
  565. 16:09going to do is we're going to actually
  566. 16:10copy the generate viewport frame
  567. 16:11function and we're going to paste that
  568. 16:13above the generatepet function inside of
  569. 16:15here and now that we have that function
  570. 16:16inside of here the first thing that we
  571. 16:17need to do is we need to actually get a
  572. 16:19clone of the pet model local pet model
  573. 16:22equals pet models and we're going to
  574. 16:24index that with the pet dot id and then
  575. 16:26once we find that we're going to clone
  576. 16:28it then we're going to call the generate
  577. 16:29viewport frame function and we're going
  578. 16:31to pass through here the
  579. 16:34clone.holder.viewportframe and we're
  580. 16:35also going to pass through the pet model
  581. 16:36as well and then really the last thing
  582. 16:38is is that whenever we click on the pet
  583. 16:39which is a text bond we want to actually
  584. 16:41do something so we're going to say clone
  585. 16:43that mouse button one click connect
  586. 16:44we're going to create a brand new
  587. 16:45function inside of here and for right
  588. 16:47now we're not going to do anything
  589. 16:48besides just print true so we can go
  590. 16:49ahead and start up our game and see if
  591. 16:51this works and we can see when we
  592. 16:52started per game we now have a pig and a
  593. 16:54cat being displayed so we have the name
  594. 16:55of the pet displayed above it and then
  595. 16:57we also have the viewport frame showing
  596. 16:58the pet model as well which means that
  597. 17:00this is working out really good if we
  598. 17:01click on the pet we can see that true is
  599. 17:03printed out as well so we know that
  600. 17:04that's working too this is perfect now
  601. 17:06we're going to start working on the info
  602. 17:08frame that appears whenever you click on
  603. 17:10a pet before we do that though what we
  604. 17:11want to do is we want to go inside of
  605. 17:13the info frame inside of the pet and
  606. 17:15inside of the viewport frame we actually
  607. 17:17want to modify the background
  608. 17:18transparency to one because we don't
  609. 17:20want there to be any background display
  610. 17:21then we're going to do is in between the
  611. 17:22generate viewport frame and the generate
  612. 17:24pep function we're going to create a
  613. 17:25brand new function called display pet
  614. 17:28info and inside of here we're going to
  615. 17:30once again accept the pet which is going
  616. 17:32to be a table now we actually need to
  617. 17:33create some variables for the info frame
  618. 17:35so below the container frame we're going
  619. 17:36to say local info equals frame dot info
  620. 17:39and then below that we're going to say
  621. 17:41local pet info equals info.pep and then
  622. 17:44that'll be good for now so back inside
  623. 17:45of the display pet info function inside
  624. 17:47of this info frame we actually display
  625. 17:49the stats of the pet so we need to get
  626. 17:51those stats and remember earlier we
  627. 17:52created a brand new config called pets
  628. 17:54and inside of that config we actually
  629. 17:56set all the stats for the specific pet
  630. 17:58and their rarity so what we're gonna do
  631. 17:59is we're gonna say local pet stat equals
  632. 18:02and we're gonna use the pets config and
  633. 18:04we're gonna index this with the name of
  634. 18:05the pet so pet dot id then we'll index
  635. 18:08the table return when we index the pet
  636. 18:10id with the pet dot rarity and that will
  637. 18:12give us the stat of the pet then we want
  638. 18:14to get the actual instance of the pet
  639. 18:15which is going to be inside of the pet
  640. 18:17inventory folder which is inside of the
  641. 18:19player so we're going to say local pet
  642. 18:20instance equals player.pet inventory and
  643. 18:24then we're going to find first child so
  644. 18:27we're going to search through this
  645. 18:27folder and we're going to search for a
  646. 18:29child name that through the uuid of the
  647. 18:31pet so that'll be afraid of those two
  648. 18:32variables what we then want to do is we
  649. 18:33want to modify the pet name text label
  650. 18:35so we're going to say head info dot pet
  651. 18:37name dot text equals pet dot id and
  652. 18:40we're gonna also use the g sub method
  653. 18:42that we use down here so we're just
  654. 18:43gonna copy and paste that then we wanna
  655. 18:44modify the rarity text label so we can
  656. 18:46just copy this and we're gonna replace
  657. 18:48pet name with rarity and now what we're
  658. 18:49gonna do is we're gonna say pet dot
  659. 18:51rarity and now remember when we modify
  660. 18:53the rarity we also wanna modify the
  661. 18:54color of the text based on the rarity of
  662. 18:56the pet and we also did that for the
  663. 18:58billboard guise that we created before
  664. 18:59as well so if we go back inside of her
  665. 19:01eggs folder inside of her handler we
  666. 19:02also have a function right here called
  667. 19:04get rarity by color and what we can do
  668. 19:05is we can go ahead and copy that and
  669. 19:07we'll paste that as the first function
  670. 19:08in our script as well so then let's say
  671. 19:10pet info dot rarity dot text color three
  672. 19:13equals get rarity color and then all we
  673. 19:16have to do is provide the pet dot rarity
  674. 19:18so now we're changing the pet name text
  675. 19:20label we're also modifying the rarity
  676. 19:21text label and the color of that as well
  677. 19:23and you know as i'm looking at this i
  678. 19:25realized that we accidentally left an
  679. 19:26extra text label in here called warning
  680. 19:28from when we actually created this you
  681. 19:30can delete that warning text label it
  682. 19:32does not mean anything and we're not
  683. 19:33going to actually use it i just
  684. 19:34completely forgot to delete it anyways
  685. 19:36now that we have that deleted the next
  686. 19:37thing we need to do is we need to
  687. 19:38actually modify the food stat and the
  688. 19:40money stat text labels inside of the
  689. 19:42stats frame so what we're going to do is
  690. 19:43we're going to say pet info dot stats
  691. 19:45frame dot food stat dot text equals and
  692. 19:48now remember when we set this text we
  693. 19:50want to prefix this with the food symbol
  694. 19:52and x so we'll say equals through symbol
  695. 19:54dot x dot dot and we're gonna combine
  696. 19:56that with the pet stat just like that so
  697. 19:59then we can duplicate this and instead
  698. 20:00of the food stat this time we're gonna
  699. 20:01modify the money stat instead of
  700. 20:03displaying the food emoji we're gonna
  701. 20:04display the bunny emoji now that we've
  702. 20:06done all that we also need to set the
  703. 20:07viewport frame as well and we're gonna
  704. 20:09do this the exact same way that we did
  705. 20:10when we generate the pet so what we're
  706. 20:12gonna do is we're just gonna copy and
  707. 20:13paste this directly into here and then
  708. 20:15we just need to provide the viewport
  709. 20:16frame so we're gonna say
  710. 20:18viewport frame petinfo.viewportframe
  711. 20:20there we go the next thing that we need
  712. 20:21to consider is the equip button whenever
  713. 20:23we click on a pet depending on if it is
  714. 20:25equipped we need to modify the equip
  715. 20:26button based off if the pet is already
  716. 20:28equipped or if it's not equipped if the
  717. 20:30player has the pet equipped already then
  718. 20:32we want to display the equip button as
  719. 20:33having a red background and we want the
  720. 20:35text to actually say unequipped because
  721. 20:37we obviously don't want the player to be
  722. 20:39able to equip a pet they already have
  723. 20:40equipped and of course on the opposite
  724. 20:42end if the pet is currently unequipped
  725. 20:44we want the button to be displayed as
  726. 20:45green and say equipped so what we're
  727. 20:47going to do is we're going to say if pet
  728. 20:48instance and we're using the pet
  729. 20:50instance because this will tell us if
  730. 20:52the pet is currently equipped pet
  731. 20:53instance dot equipped dot value then and
  732. 20:56like i said we're going to say pet info
  733. 20:58dot equip button dot text and if the pad
  734. 21:00is already equipped then we want to set
  735. 21:01this text to unequip and we're going to
  736. 21:03set the background color three of the
  737. 21:05text button to color three dot from rgb
  738. 21:08because that's what i prefer and it's
  739. 21:09going to be a reddish color so something
  740. 21:11like that and of course if the pet is
  741. 21:12not equipped then what we want to do is
  742. 21:14we want to set the text to equip and we
  743. 21:16want to set the background color instead
  744. 21:18of a red to be a green so then what we
  745. 21:20need to do is inside the generatepet
  746. 21:22function inside of where we listen for
  747. 21:24the click what we're going to do is
  748. 21:25remove this print statement then we're
  749. 21:27going to call the displaypetinfo
  750. 21:28function and we're going to pass through
  751. 21:29the pet which is the table that is
  752. 21:31passed through to the generatep function
  753. 21:32and we also want to set the visibility
  754. 21:34of the pet info frame to true so that is
  755. 21:37being displayed and we can go ahead and
  756. 21:38start our game and test that out so we
  757. 21:40can see both of our pets are being
  758. 21:41generated when we click on them we can
  759. 21:43now see that this info frame now pops up
  760. 21:45we can see the name of the pet is cat
  761. 21:46the rarity is common and it's a gray
  762. 21:48color the stats are 2.5 and we have the
  763. 21:50equip button and the delete button right
  764. 21:52here if we click on the pick we can see
  765. 21:53that the information changes so the name
  766. 21:55is pig the color is blue the rarity is
  767. 21:57rare the color of the rarity is blue the
  768. 21:59stats are 6.5 we have the equip on there
  769. 22:02and we also have the trash can as well
  770. 22:03so this is working perfectly another
  771. 22:05thing that we need to do though
  772. 22:06otherwise we're gonna have a memory leak
  773. 22:07it's back inside of the display pet info
  774. 22:09function what we need to do is every
  775. 22:11single time we call this function what
  776. 22:12we do is we clone the model of the pet
  777. 22:14and then we parent that to the viewport
  778. 22:16frame so we need to delete the old pet
  779. 22:18model before we add a new one otherwise
  780. 22:20we're gonna have a memory leak now we
  781. 22:22can do this really easily so above where
  782. 22:23we create the pet model variable we're
  783. 22:25going to say local previous model equals
  784. 22:28pet info dot viewport frame find the
  785. 22:30first child of class and now the class
  786. 22:33that we're going to be looking for is
  787. 22:34model so what this is going to do is
  788. 22:36going to look for the viewport frame and
  789. 22:37check if any of the children inside of
  790. 22:39the viewport frame is a model and if we
  791. 22:41are able to find one then what we want
  792. 22:42to do is we want to destroy them so
  793. 22:44basically every single time we call this
  794. 22:45function we're going to see if there is
  795. 22:46a model currently existing inside of the
  796. 22:48viewport frame and the first time that
  797. 22:50we call this there will not be because
  798. 22:51we of course haven't put a model in
  799. 22:53there yet but the second time that we
  800. 22:54called this function there will be a
  801. 22:56model inside of the viewport frame and
  802. 22:57then that one will be destroyed and
  803. 22:59we're basically going to replace it with
  804. 23:00a brand new one so this will patch up a
  805. 23:02memory leak which could cause your
  806. 23:03players to lag after a while the next
  807. 23:05thing we're gonna do is we're gonna
  808. 23:06actually start organizing this code a
  809. 23:08little bit which is actually why we
  810. 23:09cleared everything out of the handler
  811. 23:10script so what we're gonna basically do
  812. 23:11is we're gonna basically move everything
  813. 23:13to inside of the handler script so we're
  814. 23:14gonna copy all those variables paste
  815. 23:16them directly into there and then all of
  816. 23:17these functions that we created we're
  817. 23:19gonna paste inside of there as well so
  818. 23:21we're gonna remove them from the manager
  819. 23:22script and put them inside of the
  820. 23:24handler and then instead of saying local
  821. 23:26function for all of them we're gonna
  822. 23:27remove the local keyword and we're just
  823. 23:29gonna say module dot at the beginning of
  824. 23:31the name so once again remove local and
  825. 23:33add module to all of them as well now
  826. 23:35once we've done that for all the
  827. 23:36different functions what we then need to
  828. 23:37do is we need to update the function
  829. 23:39calls inside of here which have a red
  830. 23:40underlined to them as well so all we
  831. 23:41have to do is paste module dot next to
  832. 23:44them and that'll make sure that we're
  833. 23:45calling the function once again and
  834. 23:46there we go now all the functions have
  835. 23:48been set back up perfectly then back
  836. 23:49inside the manager we don't actually
  837. 23:51have these two functions anymore so now
  838. 23:52we have to say handler.pet
  839. 23:54instance2table and handler.generatepet
  840. 23:57as well and if we just go ahead and
  841. 23:58start this up we can see that it all
  842. 24:00should work perfectly fine uh actually
  843. 24:01one issue that we're gonna have with
  844. 24:02this is because we copy and pasted all
  845. 24:04the variables from the script into here
  846. 24:05we actually brought over the require of
  847. 24:07this specific module right here and of
  848. 24:09course if a module requires itself then
  849. 24:10there will be an error so anyway we can
  850. 24:12start this up and see that this should
  851. 24:13work perfectly fine and it does so that
  852. 24:16is perfect the next thing we're going to
  853. 24:17do is we're going to go back inside of
  854. 24:18our manager and we're going to actually
  855. 24:19start scripting the equip button which
  856. 24:21is inside of the info pet frame so this
  857. 24:24button right here so let's actually
  858. 24:25create a variable for that so we're
  859. 24:26going to say local equip button equals
  860. 24:29pet info dot equipment then we can do is
  861. 24:31before this for loop and above the exit
  862. 24:33button we're going to say equip button
  863. 24:34dot mouse button one click connect
  864. 24:36function and create a brand new function
  865. 24:37inside of here now back inside of the
  866. 24:39handler we're going to actually create a
  867. 24:40brand new variable inside of here and
  868. 24:41we're going to say module dot selected
  869. 24:44pet equals no because by default we
  870. 24:46don't want there to be any selected pet
  871. 24:48but we're going to set this variable any
  872. 24:50time that we click on a pet so if we go
  873. 24:51back to our generate pet function what
  874. 24:53we're going to do is we're going to set
  875. 24:55the selected pet variable to the current
  876. 24:57pet so back inside of the manager then
  877. 24:58what we want to do is inside of this
  878. 25:00function we're going to say if not
  879. 25:02handler dot selected pet then return end
  880. 25:05so if we don't currently have a selected
  881. 25:06pet then we're just going to not do
  882. 25:08anything otherwise we're going to use a
  883. 25:09remote function and we actually need to
  884. 25:11create this real quick so inside of the
  885. 25:12replicated storage inside of remotes
  886. 25:14we're gonna add a brand new remote
  887. 25:15function and the name of this remote
  888. 25:17function is gonna actually be called pet
  889. 25:18equip so now we're gonna say local
  890. 25:20result equals remotes dot pet equip
  891. 25:24invoke server and what we're gonna pass
  892. 25:25through the server is the handler
  893. 25:29so anytime we click on a pet it's going
  894. 25:31to set this variable to that specific
  895. 25:32pet if we try to equip it we want to
  896. 25:34tell the server and we want to give the
  897. 25:35server the uuid of the pet that we want
  898. 25:37to equip so that the server can identify
  899. 25:39it and equip it for the player if it
  900. 25:41should equip it for the player now let's
  901. 25:42think about the logic for a second
  902. 25:43behind this remote function this remote
  903. 25:45function is going to return something
  904. 25:47and let's think about what it should
  905. 25:48return well if the player is able to
  906. 25:49equip the pet then it should return
  907. 25:51equipped but then let's also think that
  908. 25:53the equip button doesn't only act as an
  909. 25:55equip button and what i mean by this is
  910. 25:57that the equip button will also say
  911. 25:59unequipped sometimes as well if the
  912. 26:00player is currently equipped so the
  913. 26:02petty quit remote function isn't only
  914. 26:03trying to equip it but it should also
  915. 26:05unequip it as well if the pet is
  916. 26:07currently equipped so we should also
  917. 26:09return unequipped and imagine if the
  918. 26:11player is not allowed to equip any more
  919. 26:12pets when they try to equip this pet
  920. 26:14then we should do is we should return
  921. 26:15full so that we know that the player
  922. 26:16cannot equip any more pets let's start
  923. 26:18doing things on the client side that we
  924. 26:20should be doing based off those results
  925. 26:22so first off if there is no result
  926. 26:23because there's some type of error all
  927. 26:25we want to do is we just want to cancel
  928. 26:27the function out right here and that's
  929. 26:28why we're saying if no result then
  930. 26:29return n then what we want to do is we
  931. 26:31want to actually find the template of
  932. 26:33that specific pet inside of our
  933. 26:35container so we're going to create a
  934. 26:36brand new variable called pet template
  935. 26:38instance and what we're gonna do is
  936. 26:39we're gonna set that to container and
  937. 26:41inside of the container we're gonna try
  938. 26:42to find the first child and the name of
  939. 26:44the child is going to be
  940. 26:46handler.selectedpet.uuid now that we
  941. 26:48found that we're gonna do things based
  942. 26:49off of the result so we're gonna say if
  943. 26:51result equals equipped then so if the
  944. 26:54pet has just been equipped then what do
  945. 26:56we need to do back inside of the gui we
  946. 26:58actually need to go inside of the info
  947. 26:59inside of the pet and now we want to
  948. 27:01modify the equip button because if we
  949. 27:02just equipped it we want the equip
  950. 27:04button to now say unequipped because if
  951. 27:06we just equip the pet we now want the
  952. 27:07bun to say unequipped and we want the
  953. 27:08background color to be red which if that
  954. 27:10sounds familiar well yeah that's
  955. 27:11actually what we did right here when we
  956. 27:13display the pet info so what we can
  957. 27:14actually do is we can copy this and
  958. 27:16paste that directly into here so if the
  959. 27:18result equals equip we're going to set
  960. 27:19the button text to display unequipped
  961. 27:21and we'll also change the background
  962. 27:22color as well and another thing that we
  963. 27:23need to do is with the pet template if
  964. 27:25we go inside of the container and inside
  965. 27:27of the template and inside the holder we
  966. 27:28can see that we have this equip text
  967. 27:30label right here we want that equipped
  968. 27:31text label to actually be displayed or
  969. 27:33visible so the player knows that that
  970. 27:35pet is currently equipped so what we're
  971. 27:37going to do is we're going to say pet
  972. 27:38template instance dot holder dot
  973. 27:41equipped dot visible equals true now
  974. 27:44where we have this else statement we're
  975. 27:45going to actually change this to an else
  976. 27:46if statement and we're going to say else
  977. 27:48if the result equals unequipped then now
  978. 27:51we're going to do the opposite we're
  979. 27:52going to set the equip button text to
  980. 27:53equipped we're going to change the
  981. 27:54background color to green and of course
  982. 27:56for this we want to set the equipped
  983. 27:57visibility inside of the pet template to
  984. 27:59false so that it's no longer displayed
  985. 28:01and remember we have one more possible
  986. 28:03result so we're going to say else if
  987. 28:04results equals full now this could just
  988. 28:07be an else statement instead of an else
  989. 28:09if statement but i like using else if
  990. 28:10statement so that we can remember what
  991. 28:12all the result values could possibly be
  992. 28:14and now if we do get full we're just
  993. 28:15gonna print out full and now that looks
  994. 28:17pretty good now we need to actually
  995. 28:18create more player info because one we
  996. 28:20need to know how many pets the player
  997. 28:22can have equipped and how many they can
  998. 28:23also have stored so back inside of the
  999. 28:25server script surface inside of the
  1000. 28:26player data script we're gonna go down
  1001. 28:27to where we just created the pet
  1002. 28:29inventory folder right here and we're
  1003. 28:30going to actually create a brand new
  1004. 28:31folder so i'm just going to copy and
  1005. 28:32paste that and change this from pet
  1006. 28:34folder to pet info so the name of this
  1007. 28:36folder is of course going to be pet info
  1008. 28:38and inside of this folder we're going to
  1009. 28:39actually create the max equipped so
  1010. 28:41we're going to say pets max equipped
  1011. 28:44equals instance dot new int value we'll
  1012. 28:47parent that to the pet info folder that
  1013. 28:48we just created we'll say pets max
  1014. 28:50equipped dot name equals max equipped
  1015. 28:53and we will set the value of this and
  1016. 28:56we'll set the value of this to three so
  1017. 28:57by default the max amount of pass the
  1018. 28:59player can have equipped is three then
  1019. 29:00we're going to do the exact same thing
  1020. 29:02but instead of for the max equipped this
  1021. 29:04is gonna be for the max stored so
  1022. 29:05instead of max equipped we're gonna say
  1023. 29:07max stored we'll change the variable for
  1024. 29:08all these and then the name of this is
  1025. 29:10of course gonna be max stored and the
  1026. 29:11default value should be 50. now the only
  1027. 29:13way that this number will ever change
  1028. 29:15usually is if the player purchases game
  1029. 29:17passes considering i'm not going to be
  1030. 29:18implementing the game passes for these
  1031. 29:20specific features and considering you
  1032. 29:22guys have watched this entire tutorial
  1033. 29:23up to this episode you guys should most
  1034. 29:25likely understand how to implement these
  1035. 29:27game passes yourself and also how to
  1036. 29:28implement the data saving yourself as
  1037. 29:30well i'm not going to be saving the data
  1038. 29:32because we're not implementing the game
  1039. 29:33passes so this number will never change
  1040. 29:35meaning we don't actually have to save
  1041. 29:36this data the same goes for this data as
  1042. 29:38well anyways now that we've created the
  1043. 29:39player data for these specific things we
  1044. 29:41then want to create a brand new server
  1045. 29:42script inside of the server script
  1046. 29:44service and we'll rename this to pets
  1047. 29:46now instead of the server script we are
  1048. 29:47going to get the replicated storage
  1049. 29:49because remember we created that pet
  1050. 29:50equip remote function and we're going to
  1051. 29:52handle that inside of here then we're
  1052. 29:53going to create a variable for remotes
  1053. 29:54and we're going to say remote is
  1054. 29:56replicated storage dot remotes then at
  1055. 29:58the bottom of our script we're going to
  1056. 29:59say remotes dot pet equip dot on server
  1057. 30:02invoke and we're going to connect that
  1058. 30:04to a brand new function so let's create
  1059. 30:05a brand new function up here we're going
  1060. 30:06to say local function pet equip and
  1061. 30:08we're going to accept the player who
  1062. 30:09called this function as a player object
  1063. 30:11and we're going to accept the uuid which
  1064. 30:13is going to be a string so then of
  1065. 30:15course on the server invoke we're going
  1066. 30:16to set that to the pet equip function
  1067. 30:18that we just created now the first thing
  1068. 30:20we're going to do inside of the pet
  1069. 30:21equipped function is that we're going to
  1070. 30:22actually see if the player has the pet
  1071. 30:24that they say that they want to equip or
  1072. 30:26unequip and the reason we're doing this
  1073. 30:27is because remember the client can
  1074. 30:29always lie to us so we need to make sure
  1075. 30:30that the information that they're
  1076. 30:31telling us can actually even be found so
  1077. 30:33we're going to say local pet equals
  1078. 30:35player dot pet inventory because that's
  1079. 30:38where all the pets are stored find first
  1080. 30:40child and then we're gonna try to find
  1081. 30:41the first child with the name of the
  1082. 30:43uuid passed to us and then if we're not
  1083. 30:45able to find that pet so if not pet then
  1084. 30:47we're just gonna return n so that we
  1085. 30:48stop the function right there now if we
  1086. 30:50are able to find the pet we actually
  1087. 30:51want to check if the pet is equipped so
  1088. 30:53we're going to say if pet dot equipped
  1089. 30:56dot value then so if the pet is equipped
  1090. 30:58then we want to actually unequip the pet
  1091. 31:00so we're going to say pet dot equip dot
  1092. 31:02value equals false and then we're just
  1093. 31:04going to return unequipped so that we
  1094. 31:06know that we did just unequip the pet
  1095. 31:08now if the pet is not equipped we want
  1096. 31:10to check if the player is able to equip
  1097. 31:12the pets what we want to do is we're
  1098. 31:13going to create a function up here
  1099. 31:15called can equip pet and inside of here
  1100. 31:18what we're going to do is we're going to
  1101. 31:19accept the player the way that we're
  1102. 31:20going to determine if the player can't
  1103. 31:21equip the pet is if the amount of pets
  1104. 31:23the player currently has equipped is
  1105. 31:24less than the max amount of pets the
  1106. 31:26player is allowed to equip we can get
  1107. 31:28the max amount of pets the players
  1108. 31:29allowed equipped easily and we'll do
  1109. 31:30this by saying local max equipped equals
  1110. 31:34player dot pet info dot max equipped
  1111. 31:38that value because remember we just
  1112. 31:39created this not too long ago inside of
  1113. 31:41the player data script now that we have
  1114. 31:42this we also need to figure out how many
  1115. 31:44pets the player currently has equipped
  1116. 31:45so we'll create a brand new function and
  1117. 31:47we'll say amount equipped and this will
  1118. 31:50also accept a player as well then we're
  1119. 31:51gonna do is we're gonna say local
  1120. 31:53equipped equals zero so we're setting
  1121. 31:54the equip variable to zero then what
  1122. 31:56we're gonna do is we're gonna loop
  1123. 31:57through all the pets that are inside of
  1124. 31:59the player's pet inventory so we're
  1125. 32:00going to say for underscore pet in
  1126. 32:03ipairsplayer.pet
  1127. 32:05inventory get children do so this is
  1128. 32:08going to loop through all the pets
  1129. 32:09inside of the pet inventory then we want
  1130. 32:10to do is we want to check if that pet
  1131. 32:13has the equip value set to true so if
  1132. 32:15pet dot equipped dot value then and if
  1133. 32:18it is set to true then what we want to
  1134. 32:20do is we want to add one to the equipped
  1135. 32:22variable and then at the end we will
  1136. 32:24return equip and this will give us the
  1137. 32:26total amount of pets that the player
  1138. 32:27currently has equipped so then back
  1139. 32:28inside the can equip pet function we're
  1140. 32:30going to say local currently equipped
  1141. 32:33equals amount equipped and we'll pass
  1142. 32:35through the player then we'll say return
  1143. 32:37currently equipped less than max
  1144. 32:39equipped so if the player currently has
  1145. 32:41less pets equipped than the max amount
  1146. 32:43that they're allowed to have then this
  1147. 32:44will return true meaning the player is
  1148. 32:46allowed to equip a pet otherwise say the
  1149. 32:48player has three pets equipped and
  1150. 32:49they're only allowed to have three
  1151. 32:50equipped then this will return false
  1152. 32:52meaning that they're not allowed to
  1153. 32:53equip any more pets and we're gonna use
  1154. 32:55this function back inside of the pet
  1155. 32:56equip function and we're gonna say else
  1156. 32:59if and we're gonna check if the player
  1157. 33:00can equip a pet by saying can equip pet
  1158. 33:02will pass through the player and if the
  1159. 33:04player is allowed to equip the pet we
  1160. 33:05already know that this pet is not
  1161. 33:07equipped so then we're gonna see if the
  1162. 33:08player is allowed to equip the pet and
  1163. 33:10if the player is allowed to equip a pet
  1164. 33:11then we're going to set the equipped
  1165. 33:13value to true so pet.equipped.value
  1166. 33:16equals trip additionally in the next
  1167. 33:18episode we'll create a pet following
  1168. 33:19system so we'll make pet follow the
  1169. 33:21player here and then also we want to
  1170. 33:23return equipped because we just equipped
  1171. 33:25the pet now finally we're going to say
  1172. 33:27else and this basically means that the
  1173. 33:28player is unable to equip the pet we're
  1174. 33:30going to return full because the player
  1175. 33:32already has the max amount of patch that
  1176. 33:34they can have equipped now that we have
  1177. 33:35that it's all created we can go ahead
  1178. 33:36and start our game and test this out so
  1179. 33:38when we press the equip on we can see
  1180. 33:39that the pet is actually now equipped we
  1181. 33:41can see this is displayed on the pet we
  1182. 33:42can now see that the equip button
  1183. 33:44displays unequip and it's red and also
  1184. 33:45if we look inside players inside of our
  1185. 33:47player inside of the pet inventory and
  1186. 33:49if we check inside of these pets
  1187. 33:50whichever one is the cat so this is the
  1188. 33:52pig this is the cat the equip should now
  1189. 33:54be set to true meaning that we now have
  1190. 33:56the pet equipped and also if we click
  1191. 33:58unequip this value should now be set to
  1192. 33:59false and we can see it is properly set
  1193. 34:01to false which means this is working
  1194. 34:03perfectly the next thing that we want to
  1195. 34:04do is we want to actually create a
  1196. 34:06warning which tells the player that
  1197. 34:07they're unable to equip any more pets
  1198. 34:08currently the way that we're going to do
  1199. 34:10this is by going into the frame and
  1200. 34:11we're just going to actually duplicate
  1201. 34:13the subtitle we'll rename this to
  1202. 34:14warning and then we're going to put this
  1203. 34:16directly above the frame make this a
  1204. 34:18little bit smaller so something like
  1205. 34:20that we'll set the text to you cannot
  1206. 34:22equip another pet exclamation mark and
  1207. 34:25we'll also set the color to a little bit
  1208. 34:27of a darkish red as well and then we
  1209. 34:29also want there to be a stroke behind
  1210. 34:30this as well so we'll set the text
  1211. 34:32stroke transparency to zero and actually
  1212. 34:33i spelled equip wrong so you cannot
  1213. 34:35equip you cannot equip another pet and
  1214. 34:38then we're gonna set the visibility of
  1215. 34:39this to false because we don't wanna
  1216. 34:40always see it so then we can go back
  1217. 34:42inside of the manager and now we're
  1218. 34:43gonna do is if the result equals full
  1219. 34:45then what we actually wanna do is
  1220. 34:46display the warning label and let's
  1221. 34:48actually create a variable for the
  1222. 34:49warning so we're going to say local
  1223. 34:51warning equals frame dot warning there
  1224. 34:53we go and if the result equals full
  1225. 34:55we're going to set warning.visible to
  1226. 34:57true so the player sees the warning and
  1227. 34:59we also want to make the warning not
  1228. 35:00visible after a couple of seconds as
  1229. 35:02well so we're gonna say test.delay we'll
  1230. 35:04let it be visible for like three seconds
  1231. 35:06we'll say function and then we're gonna
  1232. 35:07say warning dot visible equals false so
  1233. 35:10it is no longer displayed the next thing
  1234. 35:11we wanna do is we wanna calculate the
  1235. 35:13amount of pets that the player currently
  1236. 35:14has equipped so that we can change this
  1237. 35:16number directly up here so insider for
  1238. 35:18handler kind of towards the top like
  1239. 35:19right above the display pet info so
  1240. 35:21we're gonna create a new function inside
  1241. 35:22of here which is going to be called
  1242. 35:23update pets equipped and that's not
  1243. 35:26going to accept any arguments and we're
  1244. 35:28pretty much going to do the exact same
  1245. 35:29thing that we did in the amounts
  1246. 35:31equipped function up here so we can
  1247. 35:32actually just literally copy this paste
  1248. 35:34it directly inside of here and then
  1249. 35:36towards the end once we figure out how
  1250. 35:37many pets the player does have equipped
  1251. 35:39we're gonna modify the equipped text
  1252. 35:40label inside of the stats frame and
  1253. 35:42let's go ahead and create a variable for
  1254. 35:43this so right below info we're going to
  1255. 35:45create a variable for stats so we're
  1256. 35:46going to say local stats and we'll say
  1257. 35:48local equip stat equals stats dot
  1258. 35:52equipped and we'll also create a
  1259. 35:53variable for storage as well so storage
  1260. 35:56and equipped storage so back down to the
  1261. 35:59update pets equipped function we're
  1262. 36:00going to say equip stat dot text equals
  1263. 36:03and now let's look at how this text is
  1264. 36:04currently set up so we want to make sure
  1265. 36:06that we display the pet icon then we
  1266. 36:08want to display the amount that's
  1267. 36:09currently equipped dot dot and then we
  1268. 36:11want to add a slash to this and then to
  1269. 36:12the right of the slash we want to say
  1270. 36:14the max amount of pass that the player
  1271. 36:15can have equipped so the way that we get
  1272. 36:16this is by saying player dot pet info
  1273. 36:19dot max equipped dot value and that'll
  1274. 36:22give us the max amount of pass the
  1275. 36:23player is currently allowed to equip now
  1276. 36:24that we've created this function we
  1277. 36:25actually want to call this a couple of
  1278. 36:27different times so we want to call this
  1279. 36:28when the script first starts up so we're
  1280. 36:29going to say handler.updatepets equip
  1281. 36:31additionally we want to call this when
  1282. 36:33we either unequip or equip a pet as well
  1283. 36:35so we can paste that directly inside of
  1284. 36:37both of those and that's it for right
  1285. 36:39now so now that we started to update the
  1286. 36:40pets equipped text label the other thing
  1287. 36:42that we also need to do is create a
  1288. 36:43function for updating the storage label
  1289. 36:45as well and right above where we created
  1290. 36:47the update pets equip function we can
  1291. 36:48create another function and this is
  1292. 36:49going to be update pets stored now
  1293. 36:52figuring out how many pets the player
  1294. 36:53currently has stored with inside of
  1295. 36:54their inventory is extremely simple so
  1296. 36:56we're going to create a variable for
  1297. 36:57this and it's going to be called stored
  1298. 36:58and what we're going to do is we're
  1299. 36:59going to say player dot
  1300. 37:01pet inventory get children and get
  1301. 37:04children is going to return an array and
  1302. 37:05all we have to do to figure out how many
  1303. 37:06objects are inside of an array is just
  1304. 37:08add a hashtag to the beginning of this
  1305. 37:10and this will return the amount of
  1306. 37:11children that are inside of pet
  1307. 37:13inventory so now we just have to modify
  1308. 37:14the storage label and i actually messed
  1309. 37:16up the name of this variable instead of
  1310. 37:17equipped storage it should actually be
  1311. 37:20storage stat i don't know how i messed
  1312. 37:22that up but anyway going back to this
  1313. 37:23function we're going to say storage stat
  1314. 37:25dot text equals and now let's see how
  1315. 37:27this text label is actually set up so we
  1316. 37:28see that it is prefixed with this little
  1317. 37:30box emoji right there then we say the
  1318. 37:32amount that we currently have stored dot
  1319. 37:33dot we add a slash between the stored
  1320. 37:35and then we need to display the max
  1321. 37:37store that the player can currently have
  1322. 37:38and we do the basically the exact same
  1323. 37:39thing inside the update pets equipped
  1324. 37:41function right there so we can copy and
  1325. 37:42paste this and now instead of saying max
  1326. 37:44equipped we're going to say max store so
  1327. 37:45now we need to think about when do we
  1328. 37:47need to actually update the amount of
  1329. 37:48pets that the player currently has
  1330. 37:50stored inside of their inventory well
  1331. 37:51the first thing that i can think of is
  1332. 37:52that we want to call this when the
  1333. 37:54script first runs so we basically need
  1334. 37:56to update the default data inside of the
  1335. 37:57gui with the actual player data so we're
  1336. 37:59going to say update pets stored we
  1337. 38:01should also call this whenever we delete
  1338. 38:02a pet which currently we don't have that
  1339. 38:04functionality set up but that's just an
  1340. 38:06idea and then also whenever the player
  1341. 38:07obtains a new pet from hatching an egg
  1342. 38:09we also want to call this as well and
  1343. 38:10we're able to tell when a player gets a
  1344. 38:12new pet because we actually have the
  1345. 38:13remote event called pet hatched right
  1346. 38:15here and that's called whenever an egg
  1347. 38:17is hatched by the player so we can
  1348. 38:18actually listen to whenever that remote
  1349. 38:20is fired so we can say remote dot pet
  1350. 38:22hatched dot on client event connect and
  1351. 38:24then we can just simply pass through the
  1352. 38:26handler dot update pet stored function
  1353. 38:27right there so now that we have that all
  1354. 38:29set up we can see that the player
  1355. 38:30currently has two out of 50 stored pets
  1356. 38:32and then if we equip a pet we can see
  1357. 38:33this player now has one out of three
  1358. 38:35equipped and if we clip another one we
  1359. 38:36get two out of three and if we unequip
  1360. 38:38we can see one out of three now we want
  1361. 38:39to set up the functionality for actually
  1362. 38:41deleting a pet if we go inside of our
  1363. 38:43info frame inside of the pet we can see
  1364. 38:44that we actually have a delete button
  1365. 38:46right here so what we want to do is we
  1366. 38:47want to create a variable for that
  1367. 38:49delete button so we're going to say
  1368. 38:50local delete button equals pet info dot
  1369. 38:53elite button then we can listen for this
  1370. 38:54to be clicked right below the equip
  1371. 38:56button so we can say delete button mouse
  1372. 38:58button one click connect and we will
  1373. 38:59connect that to a brand new anonymous
  1374. 39:01function and now we're going to be doing
  1375. 39:02a lot of the same stuff that we did
  1376. 39:03inside of when we listened for the equip
  1377. 39:05button to be collect so we first want to
  1378. 39:06check if the handler does select the pet
  1379. 39:08is set to a pet then we also want to
  1380. 39:09create a remote event inside of our
  1381. 39:11remotes folder so we're going to rename
  1382. 39:12the remote event to pet elite then when
  1383. 39:14we click the delete button we're going
  1384. 39:15to actually fire that remote event so
  1385. 39:17we're going to say remotes dot pet
  1386. 39:18delete buyer server and we're going to
  1387. 39:20pass through the
  1388. 39:21handler.selectedpet.uuid
  1389. 39:24very similar to when we invoke the
  1390. 39:25server on the pet equipped remote
  1391. 39:27function so this is going to tell the
  1392. 39:28server that we want to delete this
  1393. 39:29specific pet and then just like how when
  1394. 39:31we equip the pet we also want to get the
  1395. 39:32pet template instance as well in this
  1396. 39:34function so we're going to get that and
  1397. 39:36then what we want to actually do is
  1398. 39:37since we're deleting it we want to
  1399. 39:38destroy this template which is held
  1400. 39:40inside of the container because we
  1401. 39:41obviously don't have this pet any longer
  1402. 39:43additionally every single time we delete
  1403. 39:45a pet we want to set the visibility of
  1404. 39:46the pet info frame to false because we
  1405. 39:48no longer want that frame to be
  1406. 39:49displayed and then when we delete a pet
  1407. 39:51we also want to update the amount of
  1408. 39:52pets that are currently stored within
  1409. 39:54the player's inventory and also if the
  1410. 39:56player had that pet equipped we also
  1411. 39:57need to update the amount of pets that
  1412. 39:58the player currently has equipped as
  1413. 40:00well so what that means is we're just
  1414. 40:01going to say handler update pet stored
  1415. 40:03and then handler update pets equip now
  1416. 40:05the one thing is that we can actually
  1417. 40:06call these functions directly after we
  1418. 40:08get the pet deleted because the way that
  1419. 40:10these functions actually work is by
  1420. 40:12going through the player's inventory and
  1421. 40:13we basically need to add a small delay
  1422. 40:15to when we call both of these functions
  1423. 40:17because the client basically needs to
  1424. 40:18wait a couple of milliseconds for the
  1425. 40:20server to actually react to the remote
  1426. 40:22that we just fired so what we're going
  1427. 40:23to do is we're going to say test.delay
  1428. 40:25and the amount of seconds that we could
  1429. 40:26put in here is like literally 0.5 it
  1430. 40:28doesn't have to wait much time at all
  1431. 40:30and then we'll just create an anonymous
  1432. 40:31function inside of here and then we will
  1433. 40:33call both of those functions inside of
  1434. 40:35this small delay so anyway now that we
  1435. 40:36created that let's go back inside of the
  1436. 40:38pet script inside of the server script
  1437. 40:39service and now we need to actually code
  1438. 40:41the functionality for deleting a pet so
  1439. 40:42let's go ahead and create a function
  1440. 40:43below the pet quip function and we're
  1441. 40:45just going to say pet delete and this is
  1442. 40:47going to accept the exact same arguments
  1443. 40:49as the equip function so it's going to
  1444. 40:50accept player and the uuid of the pet
  1445. 40:52that they want to delete and then of
  1446. 40:54course we want to check if the pet
  1447. 40:55exists so we'll just do this exact same
  1448. 40:56thing inside of this function and if we
  1449. 40:58are able to find the pet then all we
  1450. 41:00want to do is we want to destroy that
  1451. 41:01path then we'll connect the pet delete
  1452. 41:03remote event to the brand new function
  1453. 41:04that we just created so remotes that pet
  1454. 41:06delete dot on server event connect and
  1455. 41:08we'll save the pet delete function so
  1456. 41:10now let's go ahead and start up our game
  1457. 41:11and test this out so if we click on our
  1458. 41:13cat and then we click the delete button
  1459. 41:15we can see that the pet has been deleted
  1460. 41:17and we can see that the stored pets have
  1461. 41:18been updated as well and the info frame
  1462. 41:20is now not visible and we can do the
  1463. 41:22same thing with the pig and now it all
  1464. 41:23works perfectly additionally if you
  1465. 41:25wanted to you could go back inside of
  1466. 41:26the manager and you can actually set
  1467. 41:28this delay to like literally .01 and
  1468. 41:30that delay should be long enough for the
  1469. 41:32server to react to the remote firing now
  1470. 41:33another thing that we need to think
  1471. 41:34about is what if the player has the pet
  1472. 41:36inventory open on their screen and they
  1473. 41:38hatch another pet well when this happens
  1474. 41:40we want to add that pet that they just
  1475. 41:41hatched directly to their inventory to
  1476. 41:43update it and if we remember correctly
  1477. 41:44we're already listening to the pet hatch
  1478. 41:46remote event that fires whenever an egg
  1479. 41:48hatches a brand new pet the thing is
  1480. 41:49though if we go inside of the service
  1481. 41:51service and inside of the egg script
  1482. 41:52what information is actually included
  1483. 41:54with this remote event well this table
  1484. 41:56right here is actually included whenever
  1485. 41:57we fire the remote event and the only
  1486. 41:59thing that's actually inside of this
  1487. 42:00table well we can see that inside of
  1488. 42:02replicated storage inside of our configs
  1489. 42:04and inside of our eggs config so this
  1490. 42:05table for example would be included in
  1491. 42:07the pet hatch remote so we would get the
  1492. 42:09id the rarity and the chance but the
  1493. 42:11thing is that we need more information
  1494. 42:12than just what's included here the most
  1495. 42:14important thing is that we need the uuid
  1496. 42:16of the pet so what we're actually going
  1497. 42:17to do is we're going to go back inside
  1498. 42:18of the service service inside of the
  1499. 42:20utils and inside the rewards module and
  1500. 42:22when we reward a pet what we actually
  1501. 42:24want to do is we want to return that
  1502. 42:26folder instance that we just created as
  1503. 42:28well so we can actually say local pet
  1504. 42:30instance equals and now the rewards.pep
  1505. 42:32function is returning that instance to
  1506. 42:34us so then whenever we fire this remote
  1507. 42:36event to the client we can pass through
  1508. 42:37the pet and we can also pass through the
  1509. 42:39pet instance as well so then going back
  1510. 42:41inside of the manager when we listen to
  1511. 42:43the pet hash remote event on the client
  1512. 42:45what we can do is create an anonymous
  1513. 42:46function and this anonymous function is
  1514. 42:48going to accept the pet which is going
  1515. 42:50to be a table and the pet instance which
  1516. 42:52is going to be an instance and now what
  1517. 42:54we want to do with this information is
  1518. 42:56we want to generate a brand new pet and
  1519. 42:58add that directly to the container and
  1520. 42:59we already done this before right up
  1521. 43:01here inside this for loop so what we
  1522. 43:02need to do is we need to convert the
  1523. 43:04instance to a table and then we just
  1524. 43:05need to call our generatepet function so
  1525. 43:07we're literally going to copy the code
  1526. 43:08directly from there paste it in here and
  1527. 43:10now instead of saying pet we actually
  1528. 43:11want the pet instance because remember
  1529. 43:13the pet table is just a basic table from
  1530. 43:15the egg which doesn't give us enough
  1531. 43:16information that's why we created the
  1532. 43:18pet instance and now that we've done
  1533. 43:19that this should work perfectly so let's
  1534. 43:21go ahead and start up our game and see
  1535. 43:22how this works so we can see the
  1536. 43:24inventory is already open we can see
  1537. 43:25that once we hatch a pet the pet gets
  1538. 43:27added directly to our inventory and we
  1539. 43:29can keep hatching more and more pets and
  1540. 43:30we see that they keep getting added
  1541. 43:32directly to our inventory which means
  1542. 43:33this is working perfectly now one of the
  1543. 43:35last few things that we need to script
  1544. 43:36up is the multi-delete functionality and
  1545. 43:38that's this button right here so the
  1546. 43:40multi-delete functionality basically
  1547. 43:41includes clicking on this button the
  1548. 43:43info frame changes to a different info
  1549. 43:45frame from the normal pets one and then
  1550. 43:46what we want to do is we want to be able
  1551. 43:48to select a couple of different pets and
  1552. 43:49then be able to click a button which
  1553. 43:50will then delete all the pets that we
  1554. 43:52had select so what we're going to do is
  1555. 43:53we're going to go inside of the handler
  1556. 43:55and also i'm going to close this handler
  1557. 43:56which is actually from within side of
  1558. 43:58the eggs billboard gy that we created
  1559. 43:59the other day so now we just have this
  1560. 44:01handler and this manager opened up then
  1561. 44:02we're going to do is towards the top of
  1562. 44:04this we're going to create new variables
  1563. 44:05so we're going to say module dot
  1564. 44:06selected pets and this is going to be a
  1565. 44:09table so we're going to use selected
  1566. 44:10pets when we go into the multi-delete
  1567. 44:12mode and then also we're going to have
  1568. 44:13another variable called mode and by
  1569. 44:15default this is literally going to be
  1570. 44:17set to default and when we're not in
  1571. 44:18default the other mode is going to be
  1572. 44:20called delete so we're gonna have
  1573. 44:21default and delete both as modes all
  1574. 44:23right so let's go back down to the
  1575. 44:24generate pep function which is right
  1576. 44:26here currently we do these three things
  1577. 44:28whenever we click on a pet but the thing
  1578. 44:30is is that the functionality needs to
  1579. 44:32change when we click on a pet based on
  1580. 44:33the mode that we're currently in so if
  1581. 44:35we're in the multi-delete mode then what
  1582. 44:36we want to do is differently than what
  1583. 44:38we want to do when we're in the normal
  1584. 44:39default mode every time we click on a
  1585. 44:41pet so what we're going to say is if
  1586. 44:43module dot mode equals default then then
  1587. 44:46we want to do the stuff that we've
  1588. 44:48already been doing so far else now let's
  1589. 44:50go back inside of our gui and inside of
  1590. 44:52the info we have the pets frame and the
  1591. 44:53delete frame and if we look inside of
  1592. 44:55the delete frame one thing that we're
  1593. 44:56going to need to modify is the text
  1594. 44:58label called selected and if we look at
  1595. 44:59the text it says pet selected and then
  1596. 45:01the number of pets that are actually
  1597. 45:03selected at the end so let's go ahead
  1598. 45:04and create a variable towards the top of
  1599. 45:06our script for the delete info so we can
  1600. 45:08copy pet info and say delete info and
  1601. 45:10delete so now that we've got that frame
  1602. 45:12what we can do is we can come back down
  1603. 45:13to here at the bottom of this else
  1604. 45:14statement we can say
  1605. 45:15deleteinfo.selected.txt
  1606. 45:18pets selected semicolon space and then
  1607. 45:21somehow we're going to add a number to
  1608. 45:23the end of this okay so now imagine that
  1609. 45:24we're in the delete mode and we want to
  1610. 45:26start selecting pets and the way that
  1611. 45:27we're going to select pets is of course
  1612. 45:29by clicking on the pet template so what
  1613. 45:31we're going to do is when we select the
  1614. 45:32pet we're going to say table dot insert
  1615. 45:34and then the table that we're going to
  1616. 45:35be using is the module dot selected pets
  1617. 45:38and what we're going to insert into this
  1618. 45:39table is going to be the pet table that
  1619. 45:41is given to us as an argument and then
  1620. 45:43additionally if you look back inside of
  1621. 45:44the container inside of the template we
  1622. 45:46have this delete text label right here
  1623. 45:48and anytime we select the pet that we
  1624. 45:50want to delete inside of the
  1625. 45:51multi-delete mode we want to make sure
  1626. 45:53that this text label is visible so the
  1627. 45:54player knows they have this pet selected
  1628. 45:56for deletion so then what we're going to
  1629. 45:58do is we're going to say
  1630. 45:59clone.holder.delete.visible
  1631. 46:02equals true so now this is selecting the
  1632. 46:04pet and this is displaying that the pet
  1633. 46:06has been selected and now that we've
  1634. 46:07selected a pet we can actually use this
  1635. 46:09table right here to determine the amount
  1636. 46:11of pets that we currently have selected
  1637. 46:12so all we have to do is we say dot so we
  1638. 46:15can add on to the string and we're going
  1639. 46:16to say
  1640. 46:18module dot selected pets make sure you
  1641. 46:20say selected pets not selected pet and
  1642. 46:22of course the hashtag before the name of
  1643. 46:24the table will tell us how many objects
  1644. 46:25are inside of this table but now the
  1645. 46:27other thing that we have to think about
  1646. 46:28is when we click on a pet we also want
  1647. 46:30to be able to deselect them or unselect
  1648. 46:32them as well so what we should do is
  1649. 46:33inside of this l statement we should
  1650. 46:35create an if statement and what we want
  1651. 46:36to do is we want to check if the pet is
  1652. 46:38currently selected so the way that we
  1653. 46:40can do this is by saying table.find and
  1654. 46:42the table that we're going to look
  1655. 46:43through is of course the
  1656. 46:44module.selectedpets and we want to try
  1657. 46:46to find the pet so if we are able to
  1658. 46:48find the pet then we want to do
  1659. 46:49something so if the pet is not selected
  1660. 46:51then we're going to select the pet and
  1661. 46:52we're also going to display to the
  1662. 46:54player that we have selected the pet and
  1663. 46:55i think the most obvious thing that
  1664. 46:56we're going to do is if the pet is
  1665. 46:58already selected then we of course want
  1666. 46:59to set the visibility of the delete text
  1667. 47:01label to false effectively telling the
  1668. 47:02player that they have unselected that
  1669. 47:04pet and then also we want to remove that
  1670. 47:06selected pet from the table as well so
  1671. 47:08we're going to say table dot remove and
  1672. 47:10of course the table is going to be
  1673. 47:11selected pets and you might think that
  1674. 47:12you might just be able to put pet but
  1675. 47:14when you're using table remove you
  1676. 47:15actually need to put the position of
  1677. 47:17that object inside of the table and the
  1678. 47:19way that we can do that is by using
  1679. 47:20table.font table.find actually returns
  1680. 47:23the position that it found that element
  1681. 47:25inside of the array so now that we have
  1682. 47:26the functionality for selecting and
  1683. 47:28unselecting a pet and then updating the
  1684. 47:30amount of pets that are currently
  1685. 47:31selected we now have to actually script
  1686. 47:32when we click on the multi-delete button
  1687. 47:34so going back inside of our manager we
  1688. 47:36actually need to create a variable for
  1689. 47:37the multi-delete button and let's close
  1690. 47:39a lot of the stuff in our gui really we
  1691. 47:41just want the frame open we don't need
  1692. 47:42the container or the info or stats open
  1693. 47:45so now we see we have the delete button
  1694. 47:46which is actually the multi-delete
  1695. 47:47button then we'll just create a new
  1696. 47:49variable up here called multi delete
  1697. 47:51button equals frame dot delete button
  1698. 47:54and now towards the bottom of our script
  1699. 47:55above the exit button we're gonna say
  1700. 47:57multi delete button dot mouse button one
  1701. 47:59click colon connect function so now this
  1702. 48:02one is basically going to act as
  1703. 48:03swapping modes so remember we have the
  1704. 48:05default mode which basically allows you
  1705. 48:07to click on a pet and then in the info
  1706. 48:08panel it'll display the information
  1707. 48:10about the pet but then we have the other
  1708. 48:12mode we want to be able to click on
  1709. 48:13multiple different pets select them all
  1710. 48:14and then click a button inside of the
  1711. 48:16info frame which basically says delete
  1712. 48:17so those are the two modes that we have
  1713. 48:19and we're going to be using the
  1714. 48:20multi-delete button to effectively
  1715. 48:21change the mode that we currently are on
  1716. 48:23so first things first any time we click
  1717. 48:25this button we want to set the selected
  1718. 48:26pet to nil and we want to set the
  1719. 48:28selected pets to a fresh table
  1720. 48:30effectively clearing the table that was
  1721. 48:32here before then we want to check the
  1722. 48:33mode and if the mode is default then we
  1723. 48:36of course want to set the mode to not
  1724. 48:38default so our other mode is going to be
  1725. 48:39called delete additionally we want to
  1726. 48:41set the pet info frame to not visible
  1727. 48:43because we're now swapping from the pet
  1728. 48:45info mode to the delete mode and now we
  1729. 48:47need to do is we actually need to create
  1730. 48:48a variable for this delete frame inside
  1731. 48:50of the info so going back to the top we
  1732. 48:52can see pet info we'll just create a
  1733. 48:53variable called delete info which will
  1734. 48:55be for the delete frame inside of the
  1735. 48:57info frame and then after we set the pet
  1736. 48:59info frame visibility to false we want
  1737. 49:01to set the delete info frame visibility
  1738. 49:03to true and also we want to modify the
  1739. 49:05selected text to zero as well otherwise
  1740. 49:08it will always display the previous
  1741. 49:09number on here so we're going to say
  1742. 49:10delete info dot selected dot text equals
  1743. 49:14pets selected semicolon zero so now
  1744. 49:17we're all done with that and now we're
  1745. 49:18gonna say else which effectively is
  1746. 49:20saying if the handler mode is not
  1747. 49:21default so if currently we're in delete
  1748. 49:23mode and we're swapping to the default
  1749. 49:25mode then what we're gonna do is pretty
  1750. 49:26much the opposite of everything that we
  1751. 49:28do inside of here excluding this right
  1752. 49:30here so we're going to set the handler
  1753. 49:32mode from delete to default we're going
  1754. 49:34to set the pet info visible to true and
  1755. 49:36the delete info visible to false but now
  1756. 49:39we need to do one more thing and the
  1757. 49:40reason for that is because remember
  1758. 49:42inside of the handler whenever we select
  1759. 49:44the pet we set the visibility of the
  1760. 49:46delete text label inside of that clone
  1761. 49:48to true and what we want to do is
  1762. 49:49whenever we swap from the delete mode to
  1763. 49:51the normal mode we want to unselect all
  1764. 49:53those pets and visibly show that as well
  1765. 49:55so what we need to do is we need to loop
  1766. 49:57through all the pets inside of the
  1767. 49:58container so we're going to say get
  1768. 50:00children do and inside of the container
  1769. 50:02we also have a ui corner so what we're
  1770. 50:04going to do is we're going to say if not
  1771. 50:06pet is a text button then continue end
  1772. 50:09so if the child that we're looping
  1773. 50:10through in the container is not a text
  1774. 50:12bond then we're just going to continue
  1775. 50:14end oh in my apologies it's not actually
  1776. 50:15a ui corner we're looping through this
  1777. 50:17container right here and it's going to
  1778. 50:18be a ui grid layout and the reason that
  1779. 50:20we need to make this continue statement
  1780. 50:22is because of this ui grid layout so now
  1781. 50:24we basically are guaranteeing that pet
  1782. 50:25is going to be one of the templates
  1783. 50:27inside of this container and then we can
  1784. 50:28index the template by saying pet dot and
  1785. 50:31then we need to go into the holder so
  1786. 50:32pet dot holder dot delete dot visible
  1787. 50:35equals false alright so let's go ahead
  1788. 50:38and test this out so when we load into
  1789. 50:39our game we can see we have a couple of
  1790. 50:40different pets inside of inventory if we
  1791. 50:41click on a pet we can see that the info
  1792. 50:43frame is displayed as it should be if we
  1793. 50:45click on multi-delete we can now see
  1794. 50:46this multi-delete frame pop up it is
  1795. 50:48displayed and it says the pet selected
  1796. 50:50is zero if we click on a pen we can see
  1797. 50:52that this little icon pops up showing
  1798. 50:54that we have that pet selected we can
  1799. 50:55click on a couple we can also deselect
  1800. 50:57them as well and all of them are
  1801. 50:58deselected now the last thing that we
  1802. 51:00really need to do is actually script
  1803. 51:02this confirm button right here so that
  1804. 51:03we can delete all the selected pets and
  1805. 51:05also if we click the multi delete button
  1806. 51:06again all of those pets will be
  1807. 51:08unselected the info frame will be
  1808. 51:09displayed again and now we're good to go
  1809. 51:11so the next thing we need to do is we
  1810. 51:12need to create a variable for this
  1811. 51:14confirmation for the confirm button
  1812. 51:16right here inside of the delete frame so
  1813. 51:18let's go back towards the top and we can
  1814. 51:19create a variable for this so we can say
  1815. 51:21local confirmation button equals the
  1816. 51:24info dot confirmation button and there
  1817. 51:26we go and then right below where we
  1818. 51:27listen to the multi delete button mouse
  1819. 51:29button one click we can do the same
  1820. 51:31thing for the confirmation button and
  1821. 51:32then create an anonymous function just
  1822. 51:34like that alright so whenever we click
  1823. 51:35on the confirmation button what we want
  1824. 51:36to do is we want to loop through the
  1825. 51:39handler.selectedpets table that we
  1826. 51:41created and for each pet that we go
  1827. 51:42through we want to actually fire off the
  1828. 51:44pet delete remote event so we're going
  1829. 51:45to say fireserver and what we want to
  1830. 51:47pass through to the server is the
  1831. 51:48pet.uuid telling the server which
  1832. 51:50specific pet we want to delete and also
  1833. 51:52similar to how we use the delete button
  1834. 51:54up here we also need to get the pet
  1835. 51:55template instance and then we're going
  1836. 51:57to destroy that as well so we're pretty
  1837. 51:58much doing the exact same thing that we
  1838. 52:00did up here inside of this function as
  1839. 52:01well so we're going to say pet template
  1840. 52:03instance grab that instance and it's not
  1841. 52:05going to be from the
  1842. 52:05handler.selectedpet.uuid
  1843. 52:07it's going to actually be the pet.uuid
  1844. 52:09exactly how we used up here and then
  1845. 52:11we're going to find that instance and
  1846. 52:12we're going to destroy it and now we're
  1847. 52:13done with the for loop the next thing we
  1848. 52:15want to do is we want to set the
  1849. 52:16deleteinfo frame to not visible so false
  1850. 52:19and then we also want to change the mode
  1851. 52:20back to default and then we also need to
  1852. 52:22update the pets equipped and the pet
  1853. 52:24store just like how we doing this delete
  1854. 52:26function right here so let's go ahead
  1855. 52:27and copy and paste that directly into
  1856. 52:29here start per game and test this out
  1857. 52:30and see if it works alright so let's go
  1858. 52:32ahead and equip the turtle pet let's go
  1859. 52:34into multi-delete let's delete the
  1860. 52:35turtle pet the dog pet and that dog pet
  1861. 52:37as well click confirm and we can see
  1862. 52:38that every single thing's been updated
  1863. 52:40all the pets have been deleted we now
  1864. 52:42have zero pets equipped one pet stored
  1865. 52:44out of 50. we have this dog pet we can
  1866. 52:45click on that we can click multi delete
  1867. 52:47undo it everything like that it is all
  1868. 52:49working perfectly we can also look
  1869. 52:50inside of players inside of our player
  1870. 52:52inside of the pet inventory and see that
  1871. 52:53we only have this one pet left as well
  1872. 52:55so every single thing is working exactly
  1873. 52:57as it should be all right ladies and
  1874. 52:58gentlemen that's gonna be it for this
  1875. 52:59episode that's probably the longest
  1876. 53:01episode that we've had so far but i
  1877. 53:02really hope that it did help you guys
  1878. 53:03out as always if this video did help you
  1879. 53:05guys out or you guys did enjoy it make
  1880. 53:06sure to smash like button also the
  1881. 53:07subscribe button and turn this post
  1882. 53:08notifications on if you want to get
  1883. 53:10notified when i upload more roblox
  1884. 53:11development content additionally i have
  1885. 53:12a patreon if you guys like this for me
  1886. 53:14and he had access to all the scripts and
  1887. 53:15the game file they made during this
  1888. 53:16episode there's a link down below
  1889. 53:17description and you guys can go and
  1890. 53:18check that out with that being said i
  1891. 53:19hope that she has a great day and i'll
  1892. 53:20see you guys in the next episode
  1893. 53:23[Music]

About this transcript

This page contains the full transcript of Scripting the Pet Inventory Gui! Roblox Studio Simulator Guide Episode 27 by MonzterDEV, generated from the public captions YouTube serves with the video. The transcript has 14,276 words across 1,893 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.