YouTube2Text

Scripting the Pet Egg Gui! Roblox Studio Simulator Guide Episode 25 — Transcript

by MonzterDEV · 9,806 words · 1,294 segments · language en · Watch on YouTube

Full transcript

  1. 0:00what's going on ladies and gentlemen
  2. 0:00welcome back to the simulator series in
  3. 0:02today's episode we are going to be
  4. 0:03scripting the pet egg gy that we made in
  5. 0:05the last episode as always if you guys
  6. 0:07do enjoy the video or it does help you
  7. 0:08out make sure you smash the like button
  8. 0:09also the subscribe button and turn this
  9. 0:10post notifications on if you want to get
  10. 0:12notified when i upload more roblox
  11. 0:13vlogma content additionally i have a
  12. 0:15patient if you guys like this for me and
  13. 0:16gain access to all the script and the
  14. 0:17game file that make during this episode
  15. 0:19there's a link down below in description
  16. 0:20and you guys can go and check that out
  17. 0:21with that being said let's get into it
  18. 0:23so hopping directly into eating
  19. 0:24simulator to show off the functionality
  20. 0:25in the last episode we created this gui
  21. 0:27that you're seeing right here and what
  22. 0:29we're going to be doing in this episode
  23. 0:30is scripting it so the entire gui is
  24. 0:32populated with all of the individual
  25. 0:34pets as well as when we hover over them
  26. 0:35it'll display the chance of hatching
  27. 0:37that pet and we'll also implement
  28. 0:38hatching an egg and selecting a random
  29. 0:40pet for that egg and this entire system
  30. 0:42will work for multiple eggs so not just
  31. 0:44the basic egg but also another egg as
  32. 0:46well so that we can see how we can
  33. 0:47easily do this with multiple different
  34. 0:49eggs happen directly in the studio the
  35. 0:51first thing that we want to do is we
  36. 0:52want to actually add some pets to our
  37. 0:54game now i'm going to be using this free
  38. 0:55to use pet pack by azias hopefully i'm
  39. 0:57pronouncing the name correctly i'll
  40. 0:58leave a link down below in the
  41. 0:59description to get the pet pack now from
  42. 1:01this pet pack we're gonna choose just a
  43. 1:03couple of pets out of it because we're
  44. 1:04not gonna use all of them during this
  45. 1:06tutorial so the ones that i'm gonna take
  46. 1:07are the bunny the cat the dog the fox
  47. 1:10the pig and the turtle so we're gonna
  48. 1:12highlight all those hit control x then
  49. 1:14inside of the replicated storage we're
  50. 1:15gonna create a folder and we'll rename
  51. 1:17this to pets and we'll paste all the
  52. 1:19pets that we just selected directly into
  53. 1:21this folder so now that we've got a
  54. 1:22couple of our pet bottles what we then
  55. 1:23want to do is inside of the config
  56. 1:25folder we actually want to create a
  57. 1:26config module for the eggs so we'll
  58. 1:28insert a new module script and we'll
  59. 1:30rename this to eggs and then inside of
  60. 1:32the module table we'll create our first
  61. 1:34egg so we'll say basic underscore egg
  62. 1:36equals which is going to be another
  63. 1:38table and then this table is actually
  64. 1:39going to be an array of more tables so
  65. 1:41we'll create a new table inside of here
  66. 1:42and inside of here we're going to add
  67. 1:44some properties for each of the
  68. 1:45individual pets that you can hatch from
  69. 1:47this specific egg so first we're going
  70. 1:48to say id and we're going to set that to
  71. 1:50the id of the pet that we want to hatch
  72. 1:52from this egg so let's say that the dog
  73. 1:54is one of the pets that we want to hatch
  74. 1:55from this egg we can also set the rarity
  75. 1:57as well so for the dog we want a common
  76. 1:59dog to come from this egg and then we'll
  77. 2:00set the chance of hatching a dog from
  78. 2:02this egg and now this will actually be
  79. 2:03the most common pet from this egg at a
  80. 2:0515 chance then we can just copy and
  81. 2:07paste this table and just change around
  82. 2:09some of the information so the next pet
  83. 2:10that we want to be able to hatch from
  84. 2:11this is a bunny it'll also be common but
  85. 2:13the chance of this is actually going to
  86. 2:15be 10 instead of 15. we can duplicate
  87. 2:17that once again then for the cat it'll
  88. 2:19be the exact same as the bunny we want
  89. 2:20it to be common and we want it to be a
  90. 2:2210 chance we'll copy it again this time
  91. 2:24we want to hatch a fox with a 7.5 chance
  92. 2:28then a turtle which is actually uncommon
  93. 2:30and that'll have a 5 chance and lastly
  94. 2:32will be the pick which will be rare and
  95. 2:34it'll have a three percent chance of
  96. 2:36hatching now obviously you can set up
  97. 2:37the egg however you want to and all the
  98. 2:38pets as well this is of course just for
  99. 2:40demonstration purposes now we use this
  100. 2:42config file later to display all the
  101. 2:44pets which can be hatched from the egg
  102. 2:45along with their rarities and along with
  103. 2:47their chances of actually hatching those
  104. 2:48and then on the server side we'll also
  105. 2:50use this when deciding what pet to
  106. 2:52actually hatch from the x so now we need
  107. 2:53to actually create a handler for the gui
  108. 2:55or the billboard gui that we created in
  109. 2:57the last episode so inside of the
  110. 2:58starter gui we have the eggs folder and
  111. 3:00then we have our little template
  112. 3:01billboards ui right here let's go ahead
  113. 3:03and create a local script and we'll just
  114. 3:05rename this the handler then inside of
  115. 3:07here we want to get the workspace
  116. 3:08service so we're going to say local
  117. 3:10workspace equals game get service
  118. 3:11workspace and we're also going to get
  119. 3:13the replicated storage as well now we
  120. 3:15need the workspace because we want to
  121. 3:16actually get the eggs folder right here
  122. 3:18which holds all of the egg models that
  123. 3:20we're going to want to add a gui to such
  124. 3:22as the basic and the rare egg right here
  125. 3:24so we'll create a variable for the eggs
  126. 3:25folder so we'll say eggs folder equals
  127. 3:28workspace.x and now we have the eggs
  128. 3:30folder and we're also going to need to
  129. 3:31get the pep models so we'll get that
  130. 3:33from the replicated storage so pet
  131. 3:35models equals replicated storage dot
  132. 3:38pets and we could even name this pets
  133. 3:39border to keep it consistent with the
  134. 3:41eggs folder variable that we just
  135. 3:42created but we'll leave it named as pet
  136. 3:43models we're also going to need to get
  137. 3:45that egg config that we just created so
  138. 3:46we'll say local a config equals require
  139. 3:50replicatedstorage.config.x and then
  140. 3:51lastly for right now we're going to
  141. 3:52actually get the template gui which is
  142. 3:55in the same folder as our handler so
  143. 3:56we'll say local template you could name
  144. 3:58this template gy it doesn't really
  145. 4:00matter equal script dot parent dot
  146. 4:03template and now we have the template
  147. 4:04billboard gui then let's go ahead and
  148. 4:06create our first function which is
  149. 4:07actually going to be called generate
  150. 4:09billboard gui inside of here we'll
  151. 4:11accept the egg model which is going
  152. 4:12gonna be a model but we're actually
  153. 4:14gonna get the instance of a model and
  154. 4:15then we'll also pass through the egg
  155. 4:17config as well which is gonna be a table
  156. 4:19let me show you an example of how we're
  157. 4:20gonna actually be calling this function
  158. 4:22so we're gonna say generate billboard
  159. 4:23gui and for right now we'll use the eggs
  160. 4:25folder and we'll just pass through the
  161. 4:27basic egg and that'll be the egg model
  162. 4:29and then for the egg config we'll pass
  163. 4:30through the egg config dot the basic x
  164. 4:32so of course for the config it'll
  165. 4:34actually be this array right here by the
  166. 4:36way that we're calling this and then
  167. 4:37also remember inside of our egg models
  168. 4:39which is inside of here each of the egg
  169. 4:40models has an attachment inside of it so
  170. 4:42inside of our function let's go ahead
  171. 4:44and create a variable for that
  172. 4:45attachment so we'll say local attachment
  173. 4:47equals egg model dot attachment then
  174. 4:49once we have that attachment we want to
  175. 4:50actually create a clone of our template
  176. 4:52billboard gui so we'll say local clone
  177. 4:55equals template clone and then we want
  178. 4:57to make sure that we parent this and
  179. 4:58we're actually going to parent it to
  180. 4:59this folder that we're currently inside
  181. 5:01of right now which is going to be the
  182. 5:02eggs folder so we're going to maintain
  183. 5:04all of the billboard guise inside of
  184. 5:06this one folder and since we're
  185. 5:07parenting it to the folder that we're
  186. 5:08currently inside of we need to make sure
  187. 5:10that we set the adorny to the attachment
  188. 5:12so that the billboard gui is displayed
  189. 5:14on that specific attachment and then we
  190. 5:16also want to rename the gui from
  191. 5:17template to whatever the egg actually is
  192. 5:19called so we'll just say eggmodel.name
  193. 5:21then let's look inside of the actual
  194. 5:23template inside of here we can see that
  195. 5:24we have the frame and then we have the
  196. 5:25title frame which inside of here we have
  197. 5:27the title text label and the same goes
  198. 5:28for the price as well so let's set the
  199. 5:30both of those so we'll say clone dot
  200. 5:33frame dot title dot title dot text
  201. 5:36equals eggmodel.name and remember we
  202. 5:39learned about g sub in the last couple
  203. 5:40of ui tutorials this basically allows us
  204. 5:42to find and replace a specific character
  205. 5:44or set of characters within the string
  206. 5:46that we're using this method on so we'll
  207. 5:47say underscore and we're going to
  208. 5:48replace that with a space and then we
  209. 5:50also want to set the price as well so
  210. 5:52we'll say clone.frame.price.price.txt
  211. 5:56equals and now we need to make a way to
  212. 5:58figure out the price of the egg so what
  213. 6:00we'll do is we'll actually modify the
  214. 6:02egg config slightly so inside of the
  215. 6:03basic egg config we'll add a new field
  216. 6:06to this and we'll say price and we'll
  217. 6:07just say the price of this is 2 000
  218. 6:09coins now for all the pets we want to
  219. 6:11actually create another field inside of
  220. 6:13here and we want to say pets and we're
  221. 6:14going to set that equal to basically
  222. 6:16what the egg originally was which was
  223. 6:18just an array of all these different
  224. 6:20pets so the basic egg is now a table
  225. 6:22with a field of price and pets and pets
  226. 6:24is now the table which is also an array
  227. 6:26of all the individual pets with the
  228. 6:28rarities the ids and the chances so now
  229. 6:30going back to the handler we can now get
  230. 6:32the price of the egg by saying
  231. 6:34eggconfig.price so now let's go ahead
  232. 6:36and test this out the first thing that
  233. 6:37we want to make sure that we do though
  234. 6:38is for the original template we still
  235. 6:40have the adorney set for the basic egg
  236. 6:42so what we'll do is we'll just actually
  237. 6:43set that to nothing so that this doesn't
  238. 6:45automatically display on the basic egg
  239. 6:46when we start the game and we can verify
  240. 6:48that the script is working and of course
  241. 6:49make sure that you're actually calling
  242. 6:51the method and make sure that you're
  243. 6:52passing through the basic egg model and
  244. 6:53the basic egg config just exactly like
  245. 6:55how we did then we can go ahead and
  246. 6:56start this up and verify that it works
  247. 6:58so upon starting up our game we can walk
  248. 7:00over to the basic egg and we can see
  249. 7:02that the price is directly down here we
  250. 7:04have the name set to basic egg although
  251. 7:05i'm pretty sure we set that by default
  252. 7:07anyway but we are seeing that this gui
  253. 7:09is popping up which means that
  254. 7:10everything is working correctly let's
  255. 7:12quickly adjust the price though to make
  256. 7:13the string actually be displayed how we
  257. 7:14wanted to so we want to actually display
  258. 7:16our like little money icon right there
  259. 7:18and then we'll combine that with the
  260. 7:20price and that's how the price should be
  261. 7:22displayed the next thing we want to do
  262. 7:23is we want to start populating the gui
  263. 7:25with all the pets that can actually
  264. 7:26hatch from this egg so let's go inside
  265. 7:28of the replicated storage and we
  266. 7:29actually need to get and we actually
  267. 7:31need to set the primary part of every
  268. 7:33single pet model for each of the
  269. 7:35different pets because we're going to be
  270. 7:36displaying these within a viewport frame
  271. 7:38so let's go ahead and drag all these
  272. 7:40outside of the replicated storage back
  273. 7:42into the workspace so that we can
  274. 7:43actually view and see them and then
  275. 7:44we'll start with the bunny what we want
  276. 7:45to do is we want to try to set the
  277. 7:47primary part to be the main square of
  278. 7:50the actual pet so we're going to try to
  279. 7:51avoid setting something like the feet or
  280. 7:53the ears or other things like that we
  281. 7:55want to just try to set it to the main
  282. 7:56square and if you're unfamiliar with
  283. 7:57setting the primary part of a model you
  284. 7:59click on the model it has the primary
  285. 8:01part property right here and then you
  286. 8:02just click that and select whatever part
  287. 8:04you want to set the primary part to so
  288. 8:05we've got the bunny done and then for
  289. 8:07the cat we found the face so let's just
  290. 8:09go ahead and do that for the dog we
  291. 8:11found this one as well and then we just
  292. 8:12have to do it for the fox the pig and
  293. 8:14the turtle all right so now that we have
  294. 8:15the primary part set for all of those
  295. 8:17pets we can go ahead and drag them back
  296. 8:19directly into the replicated storage and
  297. 8:20then we can go back to the handler and
  298. 8:22start working on generating all those
  299. 8:24pets so we'll create a new function
  300. 8:25above the generate billboard gui
  301. 8:27function called generatepet and what
  302. 8:29this will accept is the container which
  303. 8:31is going to be a frame and the pet
  304. 8:32config which is going to be a table and
  305. 8:35what i'm referring to by the pet config
  306. 8:36is going to be any of these specific
  307. 8:38tables now how we're planning to call
  308. 8:39the function is we're going to use a for
  309. 8:41loop so we're going to say for
  310. 8:42underscore pet in ipairs eggconfig.pets
  311. 8:46and then we'll just say generatepet and
  312. 8:48we'll pass through the
  313. 8:50clone.frame.container because remember
  314. 8:52inside of the billboard gy we have this
  315. 8:54container frame right here and then we
  316. 8:56also want to pass through the pet which
  317. 8:57is going to be given to us by using this
  318. 8:59for loop and then also inside the
  319. 9:00container we already have a text button
  320. 9:02named template inside of here so inside
  321. 9:04of regenerate pet function we're going
  322. 9:05to say local clone equals
  323. 9:08container.template cologne will then set
  324. 9:10the parent of the template to the
  325. 9:12container we want to set the name of the
  326. 9:13clone to petconfig.id
  327. 9:16we want to make sure that it's visible
  328. 9:17so we'll say clone.visible equals true
  329. 9:19and then inside of the template we have
  330. 9:21the pet name and the pet rarity text
  331. 9:23labels so we want to say
  332. 9:25clone.petname.txt and we want to set
  333. 9:27that to the
  334. 9:28petconfig.id and we'll probably want to
  335. 9:30use the g sub method on this as well in
  336. 9:32case any of your pets have underscores
  337. 9:34in their name so we can just say
  338. 9:35underscore and replace that with a space
  339. 9:38and then we also want to set the pet
  340. 9:40rarity.txt to the
  341. 9:43petconfig.rarity and then also for the
  342. 9:45rarity as well we want to change the
  343. 9:47color of the rarity text based on the
  344. 9:49rarity of the pet so what i mean by that
  345. 9:51is that the common rarity is sort of a
  346. 9:53darkish gray the uncommon is a green and
  347. 9:55then the rare is a blue so then let's
  348. 9:57create a function above this function
  349. 9:59called get rarity color and we're just
  350. 10:01going to pass through the rarity which
  351. 10:02is going to be a string and then we'll
  352. 10:04say local color and we'll say if rarity
  353. 10:07equals common then color equals color
  354. 10:10three dot from rgb two five five two
  355. 10:13five five two five five as that's white
  356. 10:15and then we can pretty much just copy
  357. 10:16and paste this so we'll say else if
  358. 10:18rarity equals uncommon then and this
  359. 10:21time we want a like lightish green so
  360. 10:24maybe something like that and then we
  361. 10:25can say else but i'm just gonna create
  362. 10:27another else if statement here and we'll
  363. 10:29say else if rarity equals rare and then
  364. 10:32for this we want a kind of lightish blue
  365. 10:35so something like that and then finally
  366. 10:37we just have to return the color then
  367. 10:38we'll do is back inside the generate pet
  368. 10:40function below where we set the text of
  369. 10:42the pet rarity we're gonna say clone.pet
  370. 10:45rarity dot text color three equals get
  371. 10:48rarity color and we'll just pass through
  372. 10:50the
  373. 10:51petconfig.rarity so now we're setting
  374. 10:52the color of the text based on the
  375. 10:54rarity and now just to quickly make sure
  376. 10:55everything's going good let's go ahead
  377. 10:57and start up our game we can then come
  378. 10:58over to the gui and we can see that this
  379. 11:00is all working correctly the only thing
  380. 11:01that we really need to do is set the
  381. 11:02visibility of the default template to
  382. 11:04false so that the first one isn't
  383. 11:06displayed but we can just ignore this
  384. 11:07one for now anyway we can see the dog
  385. 11:09bunny cat fox turtle and pig are all
  386. 11:11displayed starting from common to
  387. 11:13uncommon to rare and the only thing i'm
  388. 11:15noticing is that we probably want to
  389. 11:16just change the common color from a
  390. 11:18white to a gray because i kind of messed
  391. 11:19that up but other than that everything's
  392. 11:21looking pretty good we also need to add
  393. 11:22the viewport frame and that's what we'll
  394. 11:24be doing next as well so we'll quickly
  395. 11:25adjust the common color from being white
  396. 11:27to being more of a darkish gray and that
  397. 11:29looks pretty good and now we can start
  398. 11:31working on creating the viewport frame
  399. 11:32so let's actually create a function up
  400. 11:34here called generate viewport frame
  401. 11:36inside of here what we'll accept is
  402. 11:37actually a viewport frame which of
  403. 11:39course is going to be a viewport frame
  404. 11:41and the pet model which is going to be a
  405. 11:43model so back inside of the generate pet
  406. 11:44function what we want to do is we want
  407. 11:46to get a clone of the specific pet model
  408. 11:49from a replicated storage so we'll say
  409. 11:51local pet clone equals replicate storage
  410. 11:54dot pets and then we'll index that
  411. 11:56folder with the petconfig.id
  412. 11:59and then with the model that we find
  413. 12:00we're gonna clone actually i forgot we
  414. 12:01made a variable for this so we don't
  415. 12:03have to say replicatedstorage.patch we
  416. 12:04just have to say pet models and then we
  417. 12:06have the folder so that we can index it
  418. 12:08with the id and clone it and we'll pass
  419. 12:09the viewport frame of the clone so
  420. 12:12clone.viewportframe and then we'll also
  421. 12:13pass through the pet model as well so
  422. 12:15the pet clone that we just created of
  423. 12:17course make sure your viewport frame is
  424. 12:18spelled correctly when you're passing it
  425. 12:20through here otherwise you're gonna have
  426. 12:21an error now back to the generate
  427. 12:22viewport frame function what we want to
  428. 12:24do is we want to set the primary part c
  429. 12:26frame of the pet model so we're going to
  430. 12:28say pet model set primary part c frame
  431. 12:30this is why we set the primary part on
  432. 12:32the model otherwise we wouldn't be able
  433. 12:34to do this and we're going to create a
  434. 12:36brand new c frame and what this c frame
  435. 12:38is gonna be is this is actually gonna
  436. 12:39set the position of the model that we
  437. 12:41just created so we could say zero zero
  438. 12:44zero or we don't have to put anything in
  439. 12:46here and by just saying c frame dot new
  440. 12:48that is the equivalent of saying c frame
  441. 12:50dot new and putting 0 0 0 inside of it
  442. 12:53so that's going to set the position of
  443. 12:54the model and then we'll multiply this c
  444. 12:56frame by c frame dot angles and this
  445. 12:59actually allows us to set the angle at
  446. 13:01which the model is currently positioned
  447. 13:02at so based on how our pets are
  448. 13:04currently set up and how we're going to
  449. 13:05be setting up our viewport frame and the
  450. 13:07camera for the viewport frame we want
  451. 13:08the x angle to be zero the y angle to
  452. 13:11actually be math.rad 90 because we want
  453. 13:14it to be turned to the side a little bit
  454. 13:16and then for the z angle we want this to
  455. 13:17be zero as well and now if this is
  456. 13:19confusing to you don't worry viewport
  457. 13:21frames are a little bit more complicated
  458. 13:23and see frames is also another thing
  459. 13:24that's a little bit complicated so if
  460. 13:26you don't know too much about these
  461. 13:27don't let yourself get too stumped just
  462. 13:29kind of keep following along with the
  463. 13:30tutorial and you can learn about the c
  464. 13:32frames and viewport frames on your own
  465. 13:34time in my opinion these are some really
  466. 13:35nice things and eventually you should
  467. 13:37know them but don't get stuck on them
  468. 13:38for too long if you are stumped just try
  469. 13:40to get it set up however you like it or
  470. 13:42however it'll work for your system and
  471. 13:44then try to move on from there and come
  472. 13:45back to them at a later time because
  473. 13:47from my experience when i was first
  474. 13:48starting to try to learn c frames and
  475. 13:49work with the viewport frames i had a
  476. 13:51lot of difficulty and had a lot of
  477. 13:53frustration as well so if you're in the
  478. 13:55same boat as me don't feel bad just try
  479. 13:56to keep moving on and keep learning
  480. 13:58eventually anyway now that we set the c
  481. 14:00frame of the primary part the next thing
  482. 14:01we need to do is we actually need to
  483. 14:02parent the pet model so we'll say
  484. 14:04petmodel.parent and we're going to set
  485. 14:05that to the viewport frame then we need
  486. 14:07to create a camera for the viewport
  487. 14:09frame so we'll say local camera equals
  488. 14:11instance dot new and we'll create the
  489. 14:13camera and we're going to set parent of
  490. 14:14the camera to the viewport frame and we
  491. 14:16want to set the viewport frame property
  492. 14:18called current camera to the camera that
  493. 14:20we just created and then we also need to
  494. 14:21set the c frame of the camera that we
  495. 14:23just created so we'll create a new c
  496. 14:25frame by saying c frame dot new and
  497. 14:26we'll set the position of the c frame by
  498. 14:28using vector three and we'll set that to
  499. 14:30zero zero and four and now up here i
  500. 14:33understand that when we're setting the
  501. 14:34position we're using a c frame dot nu
  502. 14:36which is slightly different than a
  503. 14:38vector3.0 but imagine that we set the
  504. 14:40position of the primary part c frame to
  505. 14:42zero zero zero now we're setting this to
  506. 14:44zero zero four which in a way sets the
  507. 14:46camera about four studs away from the
  508. 14:49actual pet model and if this is
  509. 14:50complicated for you at all think about
  510. 14:52it in this if you're taking a picture or
  511. 14:53something you don't wanna literally be
  512. 14:55inside of the thing you're taking a
  513. 14:57picture from right you want to be a
  514. 14:59little bit further away so that's why
  515. 15:00we're setting the position four studs
  516. 15:02away from what we actually set the pep
  517. 15:03model to and then for the orientation of
  518. 15:05the camera we're gonna set that to the
  519. 15:07pet model and we're gonna get the
  520. 15:08primary part of the pet model and we'll
  521. 15:10get the position of the pet model once
  522. 15:12again if you're confused at all by the
  523. 15:13viewport frames or the cameras and the c
  524. 15:16frames and everything like that don't
  525. 15:17feel bad i even struggle a little bit
  526. 15:18with this to really articulate or teach
  527. 15:21people why all this stuff comes together
  528. 15:23and what everything exactly does maybe
  529. 15:25something in the comment section could
  530. 15:26explain it better for anybody who wants
  531. 15:27to know more or understand it a little
  532. 15:29bit better i'm still not perfect or even
  533. 15:31really good when it comes to c frames
  534. 15:33and knowing everything that goes into it
  535. 15:35but i'm trying to explain the things
  536. 15:36that i really do understand and at least
  537. 15:38give us a working product so that you
  538. 15:39guys don't have to go through all the
  539. 15:41struggles of learning it all on your own
  540. 15:42alright so now that we have that
  541. 15:43function created remember we already
  542. 15:45called this when we first created the
  543. 15:46function so we cloned the actual pet
  544. 15:47model found inside of the replicated
  545. 15:49storage and then we passed that through
  546. 15:50to this function we also passed through
  547. 15:52the viewport frame as well so let's go
  548. 15:53ahead and start our game and see how
  549. 15:55these turned out so if we come over to
  550. 15:56our pet gui we can actually see all the
  551. 15:58pet models are displayed very nicely
  552. 16:01right on our gui which is really really
  553. 16:03good now let's make some minor
  554. 16:04adjustments to the actual gui itself so
  555. 16:06inside of the gui we have the container
  556. 16:08and then we have the default template
  557. 16:10right here let's make the template not
  558. 16:11visible by default and also for the
  559. 16:13viewport frame we want the background
  560. 16:15transparency to be one because we don't
  561. 16:16want to see that white background behind
  562. 16:18our pets and additionally remember
  563. 16:20inside the generate viewport frame
  564. 16:21remember how it was describing the
  565. 16:23vector3 that we created here gives us a
  566. 16:25little bit of a distance away from our
  567. 16:26pet model if we maybe wanted to make the
  568. 16:28pet appear a little bit larger or say
  569. 16:30take a picture from closer towards the
  570. 16:32pet we could change four to three and
  571. 16:34that'll basically put us a little bit
  572. 16:36closer to the pet and kind of display
  573. 16:37them as a little bit larger inside of
  574. 16:39the gui and now we see maybe even three
  575. 16:42might be a little bit better because
  576. 16:43they appear a little bit larger but the
  577. 16:44other thing that you kind of have to
  578. 16:45worry about is with the bunny we can see
  579. 16:47the ears are kind of poking out of the
  580. 16:49frame a little bit so you do have to
  581. 16:51worry about that a little bit if the
  582. 16:52distance isn't far enough away from them
  583. 16:53then all the aspects of them might not
  584. 16:55appear inside of the frame but if you're
  585. 16:57too far away from them they might appear
  586. 16:58a little bit too small for your liking
  587. 17:00so you want to find a good balance
  588. 17:01between both of those things i actually
  589. 17:03don't mind the bunny's ears popping off
  590. 17:04a little bit and i really like the size
  591. 17:06so i think we'll leave it as it's so the
  592. 17:08next thing we want to do is back inside
  593. 17:09of the generate pet function we actually
  594. 17:11want to set up displaying the chance of
  595. 17:13hatching a specific pet whenever you
  596. 17:15hover over that pet in the gui so we're
  597. 17:17gonna say clone.mouse enter which is an
  598. 17:20event of all buttons and actually to
  599. 17:21make this a little bit easier we can set
  600. 17:23the type of the clone to be a text
  601. 17:25button as that's what the clone actually
  602. 17:27is so now it'll automatically fill in
  603. 17:29when we're typing this stuff out so now
  604. 17:30we see we have mouse enter so then we
  605. 17:32can easily say connect create an
  606. 17:34anonymous function inside of here and
  607. 17:35what we want to do is whenever the mouse
  608. 17:37is hovering over the text button we want
  609. 17:39to actually set the pet rarity text to
  610. 17:41the chance of hatching the pet so we're
  611. 17:42going to say clone.pet
  612. 17:44rarity.text equals petconfig.chance
  613. 17:48and then whenever the mouse is not
  614. 17:50hovering any longer we want to say mouse
  615. 17:52leave we're going to set the pet rarity
  616. 17:54text back to the actual rarity just like
  617. 17:56that so once again we can set up our
  618. 17:58game test this out and verify that that
  619. 18:00all works going into our game hovering
  620. 18:01the mouse over it we can see that the
  621. 18:03rarity has been changed from rare to
  622. 18:05three and the same goes with all of
  623. 18:06these as well now the only other thing
  624. 18:08that we might want to do is actually add
  625. 18:09a percent symbol after the number so
  626. 18:11people understand it's gonna be like a
  627. 18:13three percent chance and etc and there
  628. 18:15we go now that's all good so now we
  629. 18:17should be pretty much done with the
  630. 18:18generate pet function let's go back to
  631. 18:19the generate billboard gui function and
  632. 18:21now if we just look back at the
  633. 18:22billboard gui we can see that we have
  634. 18:24the buttons frame right here which holds
  635. 18:26three different buttons and we of course
  636. 18:28want to do something when these buttons
  637. 18:29are clicked so we're gonna say clone dot
  638. 18:31frame dot buttons and we can start with
  639. 18:34auto dot mouse button one click connect
  640. 18:36function and then let's just duplicate
  641. 18:38this two more times so that we can
  642. 18:39listen to all the buttons being clicked
  643. 18:40so then we have times one and finally we
  644. 18:42have times three now for the auto button
  645. 18:44we most likely want to check if the
  646. 18:46player actually has this unlocked and if
  647. 18:48they do not have this unlocked we want
  648. 18:50to prompt them to purchase the game pads
  649. 18:52so depending on how you guys have your
  650. 18:54data set up for the game passes you
  651. 18:56could say if player and we actually have
  652. 18:57to get the player so let's go back up to
  653. 18:59the top and get the players service and
  654. 19:02we just create a variable for the player
  655. 19:03so local player equals players dot local
  656. 19:06player then coming back down to here we
  657. 19:07can say if player dot game passes dot
  658. 19:11times three dot value then so this mean
  659. 19:14if the player does own the game pass but
  660. 19:15let's say if the player does not own the
  661. 19:17game pass then we would want to prompt
  662. 19:19them to purchase the game pass so then
  663. 19:22you can prompt them to purchase the game
  664. 19:23pass otherwise if the player does
  665. 19:24actually own the game pass we'll do
  666. 19:26something else and we'll get to that in
  667. 19:27a minute and i actually made a mistake
  668. 19:29here i said times three realistically we
  669. 19:30would be checking the auto but we would
  670. 19:32also do the exact same thing with times
  671. 19:34three as well so instead of saying auto
  672. 19:36we're gonna check if they own the game
  673. 19:38pass by going through their player data
  674. 19:39and checking the game passes and then
  675. 19:41checking the times three and if they
  676. 19:42don't own it then we're gonna prompt
  677. 19:43them to purchase it otherwise we'll do
  678. 19:45something else as well now for times one
  679. 19:46this is gonna be the free hatching that
  680. 19:48everybody has access to you just open
  681. 19:50the egg one time simple and basic now we
  682. 19:52need to create a remote event so that we
  683. 19:53can communicate from the client to the
  684. 19:55server and tell the server hey we want
  685. 19:56to open up this ped egg right here so
  686. 19:58going back inside of the replicated
  687. 19:59storage inside the remotes we can create
  688. 20:01a new remote event and we'll just rename
  689. 20:03this to buy egg and then of course we
  690. 20:05need to create a variable for it so
  691. 20:06we'll just say local buy egg equals
  692. 20:09replicate storage that remote stop buy
  693. 20:11egg then back inside of the times one
  694. 20:13button click listener we're gonna say
  695. 20:15buy egg fire server and we'll just pass
  696. 20:17through the egg model dot id and we'll
  697. 20:19just pass through the egg model dot name
  698. 20:22and then for the auto end times three we
  699. 20:23would actually do the exact same thing
  700. 20:25but we'll pass through an extra argument
  701. 20:27so inside of the times three if the
  702. 20:28player does own this game patch what we
  703. 20:30would want to do is we would want to
  704. 20:32fire the server but instead just passing
  705. 20:34through the name of the egg we'll also
  706. 20:35pass through times three so that we know
  707. 20:37that this is sort of like the little
  708. 20:38modifier that we're gonna use while
  709. 20:40hatching the egg and this is a specific
  710. 20:41button that we pressed and we'll do the
  711. 20:43exact same thing for the auto but
  712. 20:45instead of passing through times three
  713. 20:46we'll pass through all them now i'm
  714. 20:48gonna actually comment out all of this
  715. 20:49stuff right here as we're not gonna
  716. 20:50implement the data of checking if we own
  717. 20:52the game pass or not the same goes for
  718. 20:54the times three as well so we're just
  719. 20:56gonna leave that as is otherwise we
  720. 20:57would be running into errors in our own
  721. 20:59game if you want to add the times three
  722. 21:00and the auto to your game you guys
  723. 21:02certainly can and i'm giving you guys
  724. 21:03sort of the blueprint to do that on your
  725. 21:04own now we want to create a server
  726. 21:06script for listening for the
  727. 21:07communication from the client telling us
  728. 21:08hey we want to open up this egg so let's
  729. 21:10go inside of the server script service
  730. 21:12and create a brand new script and we'll
  731. 21:14rename this to x the first thing that we
  732. 21:16want to do is we want to get the
  733. 21:17replicated storage and we also want to
  734. 21:19get the workspace as well let's create a
  735. 21:21variable for the eggs folder just like
  736. 21:23we did in our handler script so we'll
  737. 21:24say workspace.x and then we have the
  738. 21:27folder we also want to get the eggs
  739. 21:29config which we'll require from the
  740. 21:31replicatedstorage.configs.exe
  741. 21:34and then finally we want to get the buy
  742. 21:36egg remote from there replicate storage
  743. 21:38dot remotes dot by egg there we go so
  744. 21:41let's listen for the buy egg remote to
  745. 21:42be called so we'll say that on server
  746. 21:44event connect function the first
  747. 21:46argument is of course going to be a
  748. 21:48player because whenever a player calls a
  749. 21:49remote it's always going to pass through
  750. 21:51the player who called it then we'll get
  751. 21:52the egg id which is going to be a string
  752. 21:55and finally we'll get the modifier which
  753. 21:57is also going to be a string as well you
  754. 21:59could say modifier or another way to
  755. 22:00think about it is the action so times
  756. 22:02three or auto would be the action then
  757. 22:04we'd say if action
  758. 22:06equals auto then we would do something
  759. 22:08right here else if action
  760. 22:11equals times three then we would do
  761. 22:13something specific to the times three or
  762. 22:15if it doesn't equal either of those then
  763. 22:17we'll just hatch like normal and we'll
  764. 22:19create a function for hatching in a
  765. 22:20minute now the first thing we want to do
  766. 22:21whenever we call this is we want to
  767. 22:23check if the player can actually hatch
  768. 22:24the egg so we want to check first of all
  769. 22:26if the egg actually exists because an
  770. 22:28exploiter could pass a random string as
  771. 22:30the egg id and that could cause an error
  772. 22:32when we're handling this so let's go
  773. 22:33ahead and create a function called ken
  774. 22:35hatch which will accept the player as a
  775. 22:37player and the egg id as a string so
  776. 22:40first let's get the egg config so we'll
  777. 22:41say local egg config equals and then
  778. 22:44we'll index the eggs config with the egg
  779. 22:47id that were provided from the client
  780. 22:49and then we'll actually check if the egg
  781. 22:50config exists so if that config does not
  782. 22:53exist then it'll equal nil so we'll say
  783. 22:55if not a config then return n so if
  784. 22:58we're unable to find the actual config
  785. 23:00then we'll stop the function right there
  786. 23:01otherwise if we're able to find the a
  787. 23:02config then let's actually get the
  788. 23:04player's balance so the amount of money
  789. 23:06that they actually have and for us
  790. 23:08that'll be set to
  791. 23:11player.leaderstats.coms.value and then
  792. 23:12we can check if the player has enough
  793. 23:13money to actually open up the egg so if
  794. 23:15player balance is less than
  795. 23:18eggconfig.price then we're just going to
  796. 23:19return false and end so if the player
  797. 23:21does not have enough money to open the
  798. 23:23egg it'll return false and stop the
  799. 23:24script there otherwise we'll return true
  800. 23:27so if the egg config is not found
  801. 23:28because either we made a mistake or
  802. 23:30there's an explorer try to mess with our
  803. 23:31system then it'll stop the script right
  804. 23:33here and return nil we could also return
  805. 23:35false as well nil or false will work for
  806. 23:37how we're gonna use it and then we're
  807. 23:38gonna get the player's balance and we're
  808. 23:39gonna check if the player has enough
  809. 23:40money to open it if the player does not
  810. 23:42have enough money then we're just gonna
  811. 23:43return false and stop the script there
  812. 23:44another way to write this which is even
  813. 23:46cleaner is saying return if the player
  814. 23:48balance is greater than or equal to so
  815. 23:50if the player is able to hatch the egg
  816. 23:52because they either have exactly enough
  817. 23:54money or they have more money than the
  818. 23:55egg's price then we'll return the result
  819. 23:57of that so you can write this either way
  820. 23:59you want to i'm just showing you guys
  821. 24:00multiple ways of how to do that then
  822. 24:01back inside of listing the remote to be
  823. 24:03fired we're gonna say if not can hatch
  824. 24:06and we'll pass through the player and
  825. 24:07the egg id then return end so if this
  826. 24:10check does not return true then we're
  827. 24:11just gonna stop the function right there
  828. 24:13and not run anything else next let's
  829. 24:15create a function above the can hatch
  830. 24:16function and we'll actually call that
  831. 24:18hatch we'll pass through the player and
  832. 24:20the egg id now each time you open up an
  833. 24:22egg inside of a simulator you kind of
  834. 24:24have a little animation that plays which
  835. 24:25sort of acts as a small cooldown between
  836. 24:27opening x so in a way it prevents you
  837. 24:29from opening up like 20 eggs in a sec so
  838. 24:31what we'll do is we'll actually create a
  839. 24:33table called hatch cooldown and that'll
  840. 24:35equal a blank table for now and above
  841. 24:37here we want to actually create a
  842. 24:38variable for the specific cooldown and
  843. 24:40we're just going to say hatch underscore
  844. 24:42cooldown and we're going to set that to
  845. 24:43three so we'll have a three second
  846. 24:44cooldown each time a player successfully
  847. 24:46opens an egg so when we call this
  848. 24:47function the first thing that we want to
  849. 24:48do is we want to check if the player's
  850. 24:50user id is within the hatch cooldown
  851. 24:53list and if it is then we're just going
  852. 24:54to return n because we know that the
  853. 24:56player is currently on cooldown now
  854. 24:58otherwise if it's not then we're going
  855. 24:59to add their user id to the list and
  856. 25:01we'll just set it to true next we'll get
  857. 25:03the egg config just like how we did in
  858. 25:05the can hatch function right here so we
  859. 25:06can literally just copy and paste that
  860. 25:08and we also want to get the player's
  861. 25:09balance as well so we'll just do that
  862. 25:10again and similar to how we did a check
  863. 25:12inside of the ken hatch function by
  864. 25:14checking if the player has enough money
  865. 25:16to open the egg we'll also take that if
  866. 25:17statement and change it to what we
  867. 25:19originally had it so if the player
  868. 25:20balance is less than the a config.price
  869. 25:23then just return end so don't do
  870. 25:25anything below this line but if the
  871. 25:26player does have enough money to open
  872. 25:28the egg then what we want to do is we
  873. 25:29want to subtract the price of the egg
  874. 25:31from the player's balance so we'll say
  875. 25:33the player's current money minus equals
  876. 25:35a config.price and now we actually need
  877. 25:37to choose the pet from the egg that the
  878. 25:39player is going to get so another thing
  879. 25:40that we might want to do to make this a
  880. 25:42little bit better is we might only want
  881. 25:43to set the cooldown to be active if the
  882. 25:46player can purchase the egg so if the
  883. 25:47player has enough money so once we
  884. 25:49determine that the player does have
  885. 25:50enough money to purchase the egg and
  886. 25:51right before we take the player's money
  887. 25:52we'll actually set the cooldown right
  888. 25:54here now let's create a function for
  889. 25:55determining what pet the player gets
  890. 25:57from the egg that they just purchased so
  891. 25:59we'll say local function choose pet and
  892. 26:01we'll accept an argument called pets
  893. 26:02which is going to be a table so then
  894. 26:04when we call this function we're going
  895. 26:05to say local pet equals choose pet and
  896. 26:08we'll pass through the egg config.pets
  897. 26:11and remember the pets is the table right
  898. 26:13here which holds all the pets inside of
  899. 26:14it now for the choosepets function we're
  900. 26:16going to be using the logic posted to
  901. 26:17the to the developer forums by lord of
  902. 26:19watermelons so shout out to him for
  903. 26:21posting the logic to a system which will
  904. 26:23actually choose a random pet based off
  905. 26:24different rarities so with that being
  906. 26:26said what we're going to do is inside of
  907. 26:27this function we're going to create a
  908. 26:28new variable called total weight and
  909. 26:30we're going to set that to zero then
  910. 26:31we're going to loop through the pets
  911. 26:33table so in ipairs pets do and we'll add
  912. 26:36the chance of each pet to the total
  913. 26:38weight so total weight plus equals
  914. 26:40pets.chance then outside of that for
  915. 26:42loop we're going to create another
  916. 26:44variable called chance and we'll set
  917. 26:45that to math.random and this is going to
  918. 26:47spit out a number between 1 and the
  919. 26:49total weight then we'll create another
  920. 26:51variable called counter and we're gonna
  921. 26:52set that to zero and then we're gonna
  922. 26:54loop through the pets again so we'll say
  923. 26:55four underscore pet in ipairs pets do
  924. 26:58and each time we loop through we wanna
  925. 27:00add the chance of that pet to the
  926. 27:02counter and then right below that we
  927. 27:03wanna check if the chance is less than
  928. 27:05or equal to the counter and if it is
  929. 27:07then we want to return that pet and
  930. 27:09that's how we can easily choose each pet
  931. 27:11based off its rarity so now going back
  932. 27:12to the hash function we're already
  933. 27:14calling the choose pet function so then
  934. 27:15for now we can print you got a dot dot
  935. 27:18pet dot rarity dot dot space dot dot pet
  936. 27:22dot id and now that'll print to the
  937. 27:24console which pet we actually hatch
  938. 27:25every single time we hatch an egg so
  939. 27:27back down to when the buy egg event is
  940. 27:28actually called inside of the l
  941. 27:30statement we will call the hatch
  942. 27:31function we'll pass through the player
  943. 27:33and the egg id and then inside of the
  944. 27:35handler we're already calling this
  945. 27:36function so we're gonna go ahead start
  946. 27:38it up and then we can test this out so
  947. 27:39we'll come over to the egg we can see
  948. 27:40it's all displayed very nicely we can
  949. 27:42click on times one ah i see it made a
  950. 27:44slight mistake right here inside of our
  951. 27:45egg server script inside of the choose
  952. 27:47pet function i try to index pets which
  953. 27:49is the list of pets and not the
  954. 27:50individual pet with the dot chance so we
  955. 27:53need to change it from pets to
  956. 27:54pet.chance and now we can start it up
  957. 27:56and test it and it should be good so we
  958. 27:58come over to the gy we open it up and we
  959. 27:59can see that we just got a cat now we
  960. 28:01can try to open it up again but we're
  961. 28:02actually still on cooldown so we need to
  962. 28:04actually remove the cooldown from the
  963. 28:05player as we forgot to implement that
  964. 28:07back inside of the hatch function what
  965. 28:08we want to do is we want to say task dot
  966. 28:10delay and we want it to be delayed by
  967. 28:12the hash cooldown so it'll wait three
  968. 28:14seconds and then we want to create an
  969. 28:16anonymous function and then we'll set
  970. 28:17the hatchcooldown index the
  971. 28:19player.userid and we'll set it to nil so
  972. 28:21that this removes the player from the
  973. 28:23hatch cooldown list so we can start it
  974. 28:24up again and test this out let's go
  975. 28:26ahead and hatch a pet we can see we once
  976. 28:28again got the common cat we'll hatch it
  977. 28:29again and we can now see we got the fox
  978. 28:31we got the dog and if we keep hatching
  979. 28:33we'll keep seeing that we get different
  980. 28:35pets after a couple of times of hatching
  981. 28:37we actually got the turtle and we can
  982. 28:38just see from this short test right here
  983. 28:40it does seem to be working with the
  984. 28:41percentages as we still haven't gotten
  985. 28:43the pig and we only got the turtle one
  986. 28:45time out of all the times we've hatched
  987. 28:46so far now how will we communicate from
  988. 28:48the server to tell the player which pet
  989. 28:50that they actually just received well we
  990. 28:52could use a remote event so we can add a
  991. 28:53new remote event to the remotes folder
  992. 28:55and we can rename this to maybe
  993. 28:56something like pet hatched or egg hashed
  994. 28:59or something like that and then all we
  995. 29:00have to do is make a variable for this
  996. 29:02inside of our script so we can say pet
  997. 29:04patched we'll rename the variable to pet
  998. 29:06hats as well and now we can fire client
  999. 29:08with this to the player and we can pass
  1000. 29:11through the pet table and then from the
  1001. 29:12client we can listen to whenever this
  1002. 29:14remote is fired and now we can remove
  1003. 29:16this print statement and if we want to
  1004. 29:17we can go back to the handler script and
  1005. 29:19we can create a variable for this remote
  1006. 29:21so instead of just by egg we can say pet
  1007. 29:23hatch pet hatch and then we can listen
  1008. 29:25whenever this remote event's fired so on
  1009. 29:27client event connect function pet which
  1010. 29:29will be a table and we can do the print
  1011. 29:31statement that we just did on the server
  1012. 29:33end so we received a dot dot pet dot
  1013. 29:37rarity dot dot space dot dot pet dot id
  1014. 29:40and now we can start this up hatch a pet
  1015. 29:42and we can see that from the client this
  1016. 29:44is now being printed so we received a
  1017. 29:46common doll so from there you could
  1018. 29:47easily implement and add in your own
  1019. 29:49animation or your own special little gui
  1020. 29:51for whatever happens when you receive a
  1021. 29:53pet now the next thing we need to do is
  1022. 29:55add the capability of listening for
  1023. 29:57whenever a player presses either the t e
  1024. 29:59or r key on their keyboard and based off
  1025. 30:01that will perform an action of the ui so
  1026. 30:04for example if they press t we'll do the
  1027. 30:06exact same thing as if they were
  1028. 30:07clicking the times three button if they
  1029. 30:08press e will do the same thing as if
  1030. 30:10they were pressing the times one button
  1031. 30:12and if they press r we'll do the exact
  1032. 30:13same process if they click the auto
  1033. 30:15button now the way we're gonna handle
  1034. 30:16this is by using the user input service
  1035. 30:19so we're gonna get that up here now
  1036. 30:20towards the bottom of the script but
  1037. 30:21above the pet hatch remote we're going
  1038. 30:23to say user input service dot input
  1039. 30:25ended connect function and inside of
  1040. 30:27this function we'll get the input which
  1041. 30:29is an input object and game processed
  1042. 30:31event which is a bullying so the first
  1043. 30:33thing that we want to do is we're going
  1044. 30:34to say if game processed event then
  1045. 30:37return end and when the game process
  1046. 30:38event is true for the most time it's
  1047. 30:40usually if it's sort of like a hotkey
  1048. 30:42that interacts with roblox default
  1049. 30:44systems so for instance if we're
  1050. 30:45listening for the tab key to be fired
  1051. 30:47the game processed event will usually
  1052. 30:49return true because when you press tab
  1053. 30:51the leader stats leaderboard either
  1054. 30:53becomes visible or is hidden now you
  1055. 30:54might need to change this based off your
  1056. 30:56own games you could even delete it it's
  1057. 30:57not too big of a deal but we're going to
  1058. 30:59use this for now and then we also want
  1059. 31:00to check the user input type so if not
  1060. 31:03input dot user input type equals enum
  1061. 31:06dot user input type dot keyboard then
  1062. 31:09return n so if the player is not using a
  1063. 31:11keyboard then we're just gonna stop the
  1064. 31:13function there finally we can start
  1065. 31:14doing things based off of the specific
  1066. 31:16key the player presses so if
  1067. 31:18input.keycode equals
  1068. 31:20enum.keycode.and for the first one we'll
  1069. 31:22be using the t key so if it equals t
  1070. 31:25then then we'll do something else if the
  1071. 31:27keycode equals e then we'll do something
  1072. 31:30and then finally else if the key code
  1073. 31:32equals r then we'll also do something
  1074. 31:34now let's go ahead and create a function
  1075. 31:36above the generate billboard gui and
  1076. 31:38we're going to say local function
  1077. 31:40request
  1078. 31:41hatch and inside of this function we'll
  1079. 31:42accept the egg id as a string and the
  1080. 31:45action as a string as well and now we
  1081. 31:47can copy the logic that we already
  1082. 31:49created inside of each of the specific
  1083. 31:51button clicks and basically paste it
  1084. 31:53into here so first we're going to say if
  1085. 31:55action equals auto then and then we'll
  1086. 31:57paste the logic inside of here and of
  1087. 31:59course instead of firing server with the
  1088. 32:00eggmodel.name we'll fire it with the egg
  1089. 32:03id instead and the auto action as well
  1090. 32:06and then we'll say else if the action
  1091. 32:07equals times one then and then we'll use
  1092. 32:09this logic right here which once again
  1093. 32:11using the egg id instead of the
  1094. 32:13eggmodel.name and then finally you could
  1095. 32:15use an else statement or you can use an
  1096. 32:17else if statement if the action equals
  1097. 32:19times three then we will use this logic
  1098. 32:21down here so there we go now that we've
  1099. 32:24created this function and taken all the
  1100. 32:26logic from the buttons what we then just
  1101. 32:27need to do is we then just need to
  1102. 32:28recall the request hatch function with
  1103. 32:30the correct egg id and the action so
  1104. 32:32we're going to say request hatch egg
  1105. 32:34model dot name like we did previously
  1106. 32:36and then the action so if we click on
  1107. 32:38the auto button that we're going to pass
  1108. 32:39through auto if we click on the times 1
  1109. 32:41button then we're gonna pass through the
  1110. 32:42times one and if we click on the times
  1111. 32:43three button then we're gonna pass
  1112. 32:44through times three now we've created
  1113. 32:46that because we're also gonna be doing
  1114. 32:47the exact same thing down here inside of
  1115. 32:49the kiku so for t that's gonna be times
  1116. 32:51three so we're gonna say request hatch
  1117. 32:53and currently we don't have the egg id
  1118. 32:54but we'll create that in a sec so let's
  1119. 32:56just go ahead and create a variable up
  1120. 32:58here called local egg id and we'll just
  1121. 33:00set that to a blank string for this
  1122. 33:02second so that the request hatch isn't
  1123. 33:03throwing an error and remember t is
  1124. 33:05times three not auto so then we have
  1125. 33:07that set up and now for e that would be
  1126. 33:09times one and for r that is auto so now
  1127. 33:12we need to create a function for getting
  1128. 33:14the id and now the simplest way of doing
  1129. 33:16this would be getting the closest egg to
  1130. 33:17the player and seeing if they're within
  1131. 33:19the range at which the gy can be
  1132. 33:21displayed at so let's create a function
  1133. 33:23right above input ended we'll say local
  1134. 33:25function get closest egg and we won't
  1135. 33:27accept any variables so inside of this
  1136. 33:29function we're going to create a
  1137. 33:30variable called closest and we're going
  1138. 33:32to set this to a table and kind of input
  1139. 33:34fake data currently so we're going to
  1140. 33:35say egg equals nil and distance equals
  1141. 33:409999 and we'll see why we're doing that
  1142. 33:42in a second then what we're gonna do is
  1143. 33:44we're gonna loop through each of the
  1144. 33:45eggs inside of our eggs folder so four
  1145. 33:48underscore egg in eye pairs eggs folder
  1146. 33:51get children do and then we need to get
  1147. 33:54the distance so local distance between
  1148. 33:57equals player dot character dot primary
  1149. 34:00part or you could even get the humanoid
  1150. 34:02root part but we'll just say primary
  1151. 34:03part so player.character.primarypart
  1152. 34:06so basically the position of the player
  1153. 34:08minus the egg dot position that
  1154. 34:10magnitude and now we have the distance
  1155. 34:12between the two parts so then we want to
  1156. 34:13check if the distance between them is
  1157. 34:15even close enough to be displayed so if
  1158. 34:17we look inside of the template and we
  1159. 34:19look at the max distance it's 17. so we
  1160. 34:21can say if display distance is greater
  1161. 34:24than 17 then continue end so with most
  1162. 34:27likely the gy wouldn't be open because
  1163. 34:29the distance is too far then we'll go to
  1164. 34:31the next egg and check that distance now
  1165. 34:33if the distance between is small enough
  1166. 34:34meaning that they're close enough for
  1167. 34:36the gy to be open then we want to check
  1168. 34:37if closest dot distance is greater than
  1169. 34:40the distance between so basically if the
  1170. 34:42last closest egg is actually further
  1171. 34:44away than the current distance between
  1172. 34:46then we're going to set closest to a new
  1173. 34:48table with the egg equaling the egg dot
  1174. 34:50name and the distance to distance
  1175. 34:52between and that's pretty much it for
  1176. 34:54the loop so it's going to get the
  1177. 34:55distance between the player and each of
  1178. 34:57the eggs is going to check if the
  1179. 34:58distance between the player and the egg
  1180. 35:00is greater than 17 which is the max
  1181. 35:02distance that the gy can even be
  1182. 35:04displayed at then it's gonna check the
  1183. 35:05next egg and do the same thing but if
  1184. 35:07it's possible for the g wire to be open
  1185. 35:08because the distance between is smaller
  1186. 35:10than 17 it's then gonna check the last
  1187. 35:12closest distance and it's gonna compare
  1188. 35:14that to the current distance between the
  1189. 35:16player and the current egg inside of
  1190. 35:17this loop and if the previous distance
  1191. 35:19is greater than the current distance
  1192. 35:20then we're gonna update the closest
  1193. 35:22table with the new closest egg to the
  1194. 35:24player so then finally what we're gonna
  1195. 35:25say at the bottom after the for loop is
  1196. 35:27we're gonna say return closest dot egg
  1197. 35:29and then back inside of when we listen
  1198. 35:31to the input ended we're going to call
  1199. 35:33the get closes egg function and then
  1200. 35:34we'll say if not egg id then return end
  1201. 35:39so if the egg id is nil because the
  1202. 35:41player was not in the range of any of
  1203. 35:43the eggs then we're just not gonna do
  1204. 35:44anything otherwise if the player is
  1205. 35:46within the range then we're going to
  1206. 35:48fire the request hatch function which
  1207. 35:49will run one of the actions so now we
  1208. 35:51can start the game up again and test
  1209. 35:52this out so if we go over to the gui and
  1210. 35:54we click the button we can see that we
  1211. 35:56actually are hatching a pet and now if
  1212. 35:58we click the e key we can also see that
  1213. 35:59we're hashing a pet as well and we just
  1214. 36:01got the cat once again and we're
  1215. 36:02actually having weird luck we're getting
  1216. 36:04we just got the cat three times in a row
  1217. 36:05but now we see we also hatch the fox and
  1218. 36:07that's working exactly as it should so
  1219. 36:09now the final thing that we're gonna do
  1220. 36:10is create another egg config so that we
  1221. 36:12can see how we can easily call the
  1222. 36:13generate billboard for multiple eggs so
  1223. 36:15if we look inside of our eggs folder we
  1224. 36:16have the basic and the rare egg we'll
  1225. 36:18duplicate this basic egg config by
  1226. 36:19copying and pasting it just like that
  1227. 36:21and now we'll rename this from basic egg
  1228. 36:23to rare underscore egg we'll change the
  1229. 36:25price from 2000 to 5000 and now let's
  1230. 36:27say we want the dog to be rare we don't
  1231. 36:30want there to be any bunny or cat and
  1232. 36:32we'll have the fox as rare as well and i
  1233. 36:35guess that's it we'll just have the dog
  1234. 36:37and the fox both being rare and the
  1235. 36:39chances of getting these will be a five
  1236. 36:41percent and a two point five percent and
  1237. 36:43actually i messed up with the price we
  1238. 36:44want it to be five thousand not fifty
  1239. 36:46two thousand okay so there we go we now
  1240. 36:47have our quick little config set up so
  1241. 36:49right where we call the generate
  1242. 36:50billboard gui function we're gonna loop
  1243. 36:52through the eggs config so we're gonna
  1244. 36:53say for egg name comma egg config we
  1245. 36:57could say name and config but this makes
  1246. 36:59it a little bit less confusing in pairs
  1247. 37:01egg config do generate billboard gy eggs
  1248. 37:05folder and we'll index that with the egg
  1249. 37:07name comma egg config and now we can
  1250. 37:10remove the generate billboard function
  1251. 37:11because now like i said it's going to
  1252. 37:13loop through each of the eggs that we
  1253. 37:14have set up in our config and that will
  1254. 37:16call the function for each of those eggs
  1255. 37:17the other thing that we want to do is we
  1256. 37:18probably want to move the eggs a little
  1257. 37:20bit further away from each other so
  1258. 37:21we'll move this rare egg like about over
  1259. 37:23here and then we can start our game and
  1260. 37:25test this out so now we can see we can
  1261. 37:26walk over to this egg right here and we
  1262. 37:28have the basic egg being displayed with
  1263. 37:30all the pets inside of it and we can
  1264. 37:31hatch it and we see we get the common
  1265. 37:33bunny but we can also walk over to this
  1266. 37:34egg over here as well and it's displayed
  1267. 37:36a little bit further down because
  1268. 37:37remember we have the attachments set up
  1269. 37:39differently between the two but anyway
  1270. 37:41we can now see the contents of this
  1271. 37:42being generated so the rare dog and the
  1272. 37:44rare fox with their chances of hatching
  1273. 37:46so 5 and 2.5 and then we can press or
  1274. 37:49click on e and we can now see we receive
  1275. 37:51a rare dog so these are both working
  1276. 37:53exactly as they should be okay so we've
  1277. 37:55done a lot in this episode anyways
  1278. 37:57ladies and gentlemen with that all being
  1279. 37:58said i hope this guide did help you guys
  1280. 38:00out it was a lot of work and a lot of
  1281. 38:01effort if it did make sure you guys
  1282. 38:02smash the like button also hit the
  1283. 38:04subscribe button and turn suppose
  1284. 38:05notifications on if you want to get
  1285. 38:06notified when i upload more roblox
  1286. 38:07development content of course i do have
  1287. 38:09patreon if you guys like this for me and
  1288. 38:10gain access to all the scripts and the
  1289. 38:12game file i made during this episode
  1290. 38:13there's a link down below description
  1291. 38:14and you guys can go and check that out
  1292. 38:15with that being said i hope that you
  1293. 38:16guys have a great day and i'll see you
  1294. 38:18guys in the next episode

About this transcript

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