YouTube2Text

Scripting the Pet Follow System! Roblox Studio Simulator Guide Episode 28 — Transcript

by MonzterDEV · 5,522 words · 721 segments · language en · Watch on YouTube

Full transcript

  1. 0:00what's going on ladies gentlemen in this
  2. 0:01episode of the simulator series we are
  3. 0:03going to be creating the pet follow
  4. 0:04system and as always if you guys do
  5. 0:06enjoy the video or it does help you out
  6. 0:07make sure you smash like button also
  7. 0:08subscribe button and turn US Post
  8. 0:09notifications on if you want to get
  9. 0:11notified want to upload more of Roblox
  10. 0:12moment content additionally I have a
  11. 0:14patreon if you guys like to support me
  12. 0:15and gain access to all the scripts and
  13. 0:16the game file that I've made in this
  14. 0:18episode there's a link Down Below in the
  15. 0:19description and you guys can go and
  16. 0:20check that out with that being said
  17. 0:21let's get right into it so happen
  18. 0:22directly and eating simulator to see
  19. 0:24their pet follow system whenever we
  20. 0:26spawn in all of our pets that we have
  21. 0:27equipped spawn in with us and they do
  22. 0:29begin to follow us their rotation also
  23. 0:31does change depending on what our
  24. 0:32rotation currently is and if we go
  25. 0:34inside of our pet inventory and we equip
  26. 0:36a new pet we can see that pet is now
  27. 0:38following us as well and positioned
  28. 0:39correctly additionally if we unequip a
  29. 0:41pet the pet is no longer following us
  30. 0:43the same also goes if we delete a pet
  31. 0:45that's currently following us as well
  32. 0:46that pet will stop following us so now
  33. 0:48if the system explained let's hop
  34. 0:49directly in a Roblox studio so once we
  35. 0:51get into Roblox Studio the first thing
  36. 0:52we want to do is we want to go to the
  37. 0:53server script service and look inside of
  38. 0:55the pet script now inside of the script
  39. 0:57we're going to create a brand new
  40. 0:58function towards the top of our our
  41. 1:00script and that is going to be called
  42. 1:01pet follow-up now this function is going
  43. 1:03to accept a player and the pet which is
  44. 1:05actually going to be an instance this
  45. 1:07instance is actually going to be the
  46. 1:08folder that's stored inside of the
  47. 1:09player's pet inventory which includes
  48. 1:11all the information about the pet now
  49. 1:13the first thing we want to do inside of
  50. 1:14this function is we want to actually
  51. 1:15find the player's character and the way
  52. 1:17that we're going to do that is by just
  53. 1:18saying player dot character now we need
  54. 1:20to check if this character is actually
  55. 1:22existing so we're going to say if not
  56. 1:24character then return end so stop the
  57. 1:27function right there if the character
  58. 1:28does not exist and now the next thing we
  59. 1:30need to do is we need to either create a
  60. 1:32folder or check if the folder already
  61. 1:34exists inside of the player's character
  62. 1:36for where we're going to be storing the
  63. 1:37pet models that are going to be
  64. 1:38following the player so we're going to
  65. 1:40say local pets folder equals character
  66. 1:42find first child pets and that's going
  67. 1:45to be the name of the folder and then
  68. 1:46what we want to do is we want to say if
  69. 1:48not pets folder so if that folder was
  70. 1:50not found then what we want to do is we
  71. 1:51want to actually create the folder so
  72. 1:53we're going to say pets folder equals
  73. 1:55instance dot new and we're going to
  74. 1:57create a brand new folder and we're
  75. 1:58going to parent that to the players
  76. 1:59character then we're gonna set the name
  77. 2:01of this folder to pets and there we go
  78. 2:03we've now created the folder and we'll
  79. 2:04only ever create this one time after
  80. 2:06that the pets folder will be set right
  81. 2:08here because we will be able to find
  82. 2:09that folder within the character then
  83. 2:10the next thing we need to do is we need
  84. 2:12to actually get the model of the pet
  85. 2:13that we have stored with inside of the
  86. 2:16replicated storage and inside of the
  87. 2:17Pet's folder so we're going to say local
  88. 2:19pet model equals replicate storage dot
  89. 2:22pets find first child pet and now
  90. 2:24remember this is the instance that we
  91. 2:26created in the last episode if you guys
  92. 2:27are a little bit confused about that we
  93. 2:28can go inside of the utils folder and
  94. 2:30inside of the rewards module and inside
  95. 2:32of here this is one of the areas where
  96. 2:33we actually create this folder so we
  97. 2:34have a folder the name of that folder is
  98. 2:36the uuid of the pet and then inside of
  99. 2:38that folder there are two string values
  100. 2:39and one bull value and the string value
  101. 2:41that we're going to be using right now
  102. 2:42is the ID now I'm only showing you guys
  103. 2:44this to give you a reference back to the
  104. 2:45last episode when we actually created
  105. 2:47this so hopefully you guys are not
  106. 2:48confused at all by what we're indexing
  107. 2:50or what we're getting when we actually
  108. 2:51look inside of the pet instance so we're
  109. 2:54gonna say pet thought ID to get the
  110. 2:55string value and then we want to get the
  111. 2:56value of that ID because that will tell
  112. 2:58us a specific pet that we're looking for
  113. 3:00and then once we actually find that
  114. 3:02model what we then want to do is we want
  115. 3:03to clone it now that we have a clone of
  116. 3:05the pet model what we then want to do is
  117. 3:06we want to set the position of the pet
  118. 3:08to the player's character and now we're
  119. 3:10not getting the correct Auto completion
  120. 3:11right here so what I'm going to do is
  121. 3:12I'm going to actually annotate the type
  122. 3:14of this pet model to a model to tell
  123. 3:16Studio that it is a model which it will
  124. 3:18be so then we can just type in p and now
  125. 3:20we see the pivot 2 method so we can use
  126. 3:22that and now the Target c-frame that we
  127. 3:24want to use is the character that
  128. 3:25humanoid root part make sure all the
  129. 3:28capitalizations are correct and then dot
  130. 3:30C frame so now we set the position of
  131. 3:32the pet to the player what we're now
  132. 3:33going to do is basically create the
  133. 3:34opponents which will move and rotate the
  134. 3:36pet around the player whenever the
  135. 3:38player moves so we're going to create an
  136. 3:39attachment and we're going to attach
  137. 3:41this to the character's humanoid root
  138. 3:43part so we're going to say local
  139. 3:44character attachment equals instance dot
  140. 3:48new attachment and we're going to parent
  141. 3:49that to the character.humanoid root part
  142. 3:52and we want to set this attachment
  143. 3:54visibility to false so that we don't
  144. 3:56actually see that now we're going to
  145. 3:57actually create another attachment and
  146. 3:58this time we're actually going going to
  147. 4:00attach that to the pet model's primary
  148. 4:02part so what we can do is we can
  149. 4:03literally copy what we just did and
  150. 4:05rename this from character attachment to
  151. 4:07pet attachment and of course we want to
  152. 4:08copy that variable down here and now
  153. 4:10when we set the parent once again we
  154. 4:12want to set the parent to the pet model
  155. 4:13dot primary part and the visibility is
  156. 4:16going to be false for this as well next
  157. 4:17we want to actually create an align
  158. 4:19position so we're going to say local
  159. 4:20align position equals instance dot new
  160. 4:24align position and this is going to be
  161. 4:26parented to the pet model then we have
  162. 4:28to set a couple of different properties
  163. 4:29of the Align position so the first one
  164. 4:30that we want to set is the max force and
  165. 4:32we're going to set this to 25
  166. 4:34000 and then we actually need to set
  167. 4:36both the attachment properties to the
  168. 4:38attachments that we just created so
  169. 4:39we're going to say line position dot
  170. 4:40attachment zero and we're going to set
  171. 4:42that to the pet attachment and then for
  172. 4:44the attachment one we're gonna set that
  173. 4:45to the character attachment then we want
  174. 4:47to set the responsiveness of the Align
  175. 4:49position and we're going to set that to
  176. 4:5125. now we're done with the Align
  177. 4:52position for right now the next thing
  178. 4:53that we need to create is the Align
  179. 4:55orientation so we're going to say local
  180. 4:56align orientation equals instance dot
  181. 5:00new align orientation and once again
  182. 5:02that's going to be parented to the Pet
  183. 5:04Mount now we need to set some properties
  184. 5:05for this similar to the ones that we
  185. 5:06just set for the Align position so for
  186. 5:08the Align orientation we're going to set
  187. 5:10the max torque and that's also going to
  188. 5:12be set to 25 000 and then once again we
  189. 5:14need to set the attachment for this as
  190. 5:15well so we're going to say a line
  191. 5:16orientation dot attachment zero equals
  192. 5:19pet attachment and then align
  193. 5:21orientation dot attachment one equals
  194. 5:24character attachment and then finally we
  195. 5:26need to set the responsiveness of this
  196. 5:27and that's also going to be to 25 as
  197. 5:29well the next thing that we're going to
  198. 5:30do is we're going to create an INT value
  199. 5:32which is going to hold a number based on
  200. 5:34the order that the pet was equipped now
  201. 5:36the reason that we're going to do this
  202. 5:37is because imagine that you're equipping
  203. 5:38a couple of different pets depending on
  204. 5:40how many pets you have equipped you need
  205. 5:42to position each of the pets in a
  206. 5:44different position to prevent them all
  207. 5:45from being within the same exact
  208. 5:47position so we can say local order
  209. 5:49equals instance dot new int value and
  210. 5:52parent that to the pet model and we're
  211. 5:53going to set the name of this in value
  212. 5:54to order now to set the value of the
  213. 5:57order we actually need to create a
  214. 5:58function so that we can figure out out
  215. 6:00what number we want to set this Pet's
  216. 6:02order to so above the pet follow
  217. 6:03function we're going to create a new
  218. 6:05function and that's going to be called
  219. 6:06get pet order and all we need is a
  220. 6:09character which is of course going to be
  221. 6:10a model the first thing that we're going
  222. 6:12to do is we're going to create a
  223. 6:12variable for the pets folder and we're
  224. 6:14going to set that equal to character dot
  225. 6:16pets now that we have the pets voter
  226. 6:18what we first want to do is we want to
  227. 6:19check if there are any pets currently
  228. 6:21with inside of this folder if there are
  229. 6:23no pets inside of this folder then we
  230. 6:24know automatically that the order should
  231. 6:26be one because that would be the first
  232. 6:27pet going into this folder the way that
  233. 6:29we can do this is we can say if hashtag
  234. 6:31pet folder get children equals zero then
  235. 6:34return one so if there are zero children
  236. 6:36with inside of the pets folder then
  237. 6:38we're going to return one as the order
  238. 6:39now if there are children inside this
  239. 6:41folder the next thing we want to do is
  240. 6:42we want to create a variable for all of
  241. 6:44the active slots which are currently
  242. 6:46taken up then what we're going to do is
  243. 6:47we're going to Loop through all the pets
  244. 6:48inside of the pet folder so we're going
  245. 6:50to say pet folder get children do then
  246. 6:52we're gonna get the order of the pet so
  247. 6:54we're gonna say local order equals pet
  248. 6:56dot order dot value because remember we
  249. 6:58just created that down here we haven't
  250. 7:00set the value yet but we're going to set
  251. 7:01the value based off this function so
  252. 7:02don't worry about that that value will
  253. 7:04exist and then we want to use the order
  254. 7:06that we just got to set the active slots
  255. 7:08so we're going to say active slots order
  256. 7:10equals order so we're now tracking each
  257. 7:12of the orders and putting them inside of
  258. 7:14the active slots table then the next
  259. 7:15thing we want to do is we want to create
  260. 7:16another for Loop and we're going to say
  261. 7:18four available slot and this is going to
  262. 7:21be set to one I know it's really weird
  263. 7:22using the standard for Loop but that's
  264. 7:24we're going to be using for this then we
  265. 7:25have to identify the max amount of Loops
  266. 7:27that this for Loop can actually go
  267. 7:28through so this should realistically be
  268. 7:30the max amount of pets that a player can
  269. 7:31actually have equipped and I'm just
  270. 7:32going to set it to five for this example
  271. 7:34then we have to indicate how much we
  272. 7:35want to increase available slot by each
  273. 7:38Loop and we're going to say one then
  274. 7:39we'll say do and now we have our for
  275. 7:41Loop created then we want to do is we
  276. 7:42want to check if the active slot
  277. 7:44contains the available slot which would
  278. 7:46be a number so in the first Loop it
  279. 7:48would be one then two then three then
  280. 7:50four and then go all the way up to five
  281. 7:51and then the first number that active
  282. 7:53slots does not contain we are going to
  283. 7:55return that available slot so we're
  284. 7:57going to return that number and we need
  285. 7:59to make sure that we say not active slot
  286. 8:00because we're looking to see if it
  287. 8:02doesn't exist so now imagine if inside
  288. 8:03of active slots the numbers are one and
  289. 8:06three inside of this for loop it's gonna
  290. 8:07go through the first Loop and it's gonna
  291. 8:08say okay one exists so we're not going
  292. 8:10to do anything then it's going to check
  293. 8:11if two exists inside of active slot it's
  294. 8:14going to see that two does not exist so
  295. 8:15that slot is free and then it's going to
  296. 8:17return two so then we know that we're
  297. 8:18going to set the order value of this pet
  298. 8:20to that number so then we can come back
  299. 8:22down to the pet follow function and
  300. 8:23underneath where we set the name of the
  301. 8:25order instance we can also set the value
  302. 8:26as well and we're going to set that to
  303. 8:28get pet order and all we have to do is
  304. 8:30pass through the player's character so
  305. 8:32after we get the order we actually have
  306. 8:33to set the position of the pet now what
  307. 8:35we're going to do is above the get order
  308. 8:36function we're actually going to create
  309. 8:38a new table and it's going to be called
  310. 8:39pet positions now this table is actually
  311. 8:41going to be array which is going to hold
  312. 8:43more tables the tables inside of here
  313. 8:45are going to have two properties the
  314. 8:46position property and this is actually
  315. 8:48going to hold the position of where the
  316. 8:49pet should be and the position is going
  317. 8:51to be a vector three and for the first
  318. 8:52position we most likely want the pet
  319. 8:54directly behind the player so we're
  320. 8:55gonna say zero comma one comma 10 and
  321. 8:58then the other property that this table
  322. 8:59is going hold is orientation and we're
  323. 9:01going to set that to once again a vector
  324. 9:03three and this is going to be 0 negative
  325. 9:0590 0. and now the orientation is the way
  326. 9:07that the pet is facing and of course the
  327. 9:09position is how far the pet is gonna be
  328. 9:11from The Plight and we will create more
  329. 9:13of these so that each pet that we have
  330. 9:14equipped can have its own position but
  331. 9:16for now we'll go back to the pet
  332. 9:17function and we'll actually set the
  333. 9:18Pet's position so we're gonna say local
  334. 9:19pet position and we're gonna get that
  335. 9:21from the pet positions table that we
  336. 9:22just created and we're actually gonna
  337. 9:24Index this table with the order dot
  338. 9:27value that we just set so now once we
  339. 9:28have the specific pets position what
  340. 9:30we're then going to do is we're going to
  341. 9:31set the character's attachment that
  342. 9:33position to the pet positions dot
  343. 9:35position and then we're also going to
  344. 9:37set the character attachment.orientation
  345. 9:39to the pet
  346. 9:41positions.orientation and now make sure
  347. 9:43that you're setting it to the variable
  348. 9:44that we just created and not to the
  349. 9:46table that we just created which is what
  350. 9:47I did so now that is set up correctly
  351. 9:49then finally what we're gonna do is we
  352. 9:51need to set the pet model dot name to
  353. 9:54the actual uuid of the pet so that we
  354. 9:56can easily find it in case we want to
  355. 9:58destroy it and now remember the uuid
  356. 10:00would be the name of this pet so we're
  357. 10:01going to say pet dot name and then we
  358. 10:03also need to set the parent of the model
  359. 10:05as well so petmodel dot parent equals
  360. 10:07the pet folder that we just created and
  361. 10:09then lastly we need to set the network
  362. 10:10ownership of this pet so we're going to
  363. 10:12say petmodel dot primary part set
  364. 10:15network owner and we're going to set
  365. 10:17that to the player okay so we now have
  366. 10:18the pet follow function basically
  367. 10:20created then we actually need to call
  368. 10:21this function and when are we going to
  369. 10:22call this function well whenever we
  370. 10:24actually equip a pet which we have a
  371. 10:25comment laid out right here for us so
  372. 10:27we're going to say pet follow and we'll
  373. 10:29pass through the player and the pet
  374. 10:30instance now let's go ahead and start
  375. 10:32the game and test this function out so
  376. 10:33now when we hop into our game let's go
  377. 10:35ahead and equip this cat pet and we can
  378. 10:36see that the pet actually does appear
  379. 10:38behind us and it is following us so we
  380. 10:40can tell that this is working perfectly
  381. 10:42so now that we know that this pet is
  382. 10:43following us successfully the next thing
  383. 10:45we need to actually do is set up more
  384. 10:46pet positions so that we can equip more
  385. 10:48pets so going back to the pet positions
  386. 10:50let's talk about the position currently
  387. 10:52now if you're unaware of how Vector
  388. 10:53threes work this is the X this is the Y
  389. 10:55and this is the Z the Y usually
  390. 10:57indicates up and down the action usually
  391. 11:00indicates left or right and then the Z
  392. 11:01usually indicates basically forward or
  393. 11:04behind the character so the reason that
  394. 11:05this is that 10 is because this means
  395. 11:07that the pet appears 10 studs behind the
  396. 11:09player if we set this to five then the
  397. 11:11pet would actually appear five studs
  398. 11:13behind the player so this would be
  399. 11:14closer to the player now if we want to
  400. 11:16make the pet higher up off of the ground
  401. 11:17and higher above the player we could set
  402. 11:19this to five and they would probably be
  403. 11:21much higher than the player currently is
  404. 11:22so now that we understand how the
  405. 11:24position Works let's talk about the
  406. 11:25orientation the orientation is what the
  407. 11:27pet is currently facing and we figured
  408. 11:29out that the Y value of the vector 3
  409. 11:31basically makes the pet look left or
  410. 11:33right and the reason that we have the
  411. 11:34orientation set to negative 90 degrees
  412. 11:36is because we have the pet behind the
  413. 11:38players so we need to set the
  414. 11:39orientation for the pet to be facing the
  415. 11:42player now you can easily modify these
  416. 11:43numbers to work with it yourself and
  417. 11:45learn more about the orientation and the
  418. 11:46position but I have a list of my own
  419. 11:48preset positions and orientations which
  420. 11:50will work so that's what we're going to
  421. 11:51use for now so for the second position
  422. 11:53we can just copy and paste this and now
  423. 11:55all we have to do is modify a little bit
  424. 11:56of the position and the orientation so
  425. 11:58for the second and the third pet we most
  426. 12:00likely want those to appear behind the
  427. 12:01player as well one to the left and one
  428. 12:03to the right so when the player has all
  429. 12:05three pets equipped one is directly
  430. 12:06behind them and one is to the left and
  431. 12:08the right behind them as well so for
  432. 12:10this to work we are going to set the x
  433. 12:12to negative 7.5 the Y is going to stay
  434. 12:14the same the Z is actually going to be a
  435. 12:16little bit smaller and this is going to
  436. 12:17be set to eight then we also need to
  437. 12:19change the rotation a little bit because
  438. 12:20we need it to be rotated a little bit
  439. 12:22more so we're going to set that to
  440. 12:23negative 120. then for the third
  441. 12:25position we want this pet to be on the
  442. 12:27other side so like let's say for
  443. 12:28instance if the second position is on
  444. 12:30the left of the player we want this to
  445. 12:31be on the right of the player so instead
  446. 12:33of saying negative 7.5 we can actually
  447. 12:35set this to a positive 7.5 and then for
  448. 12:37the orientation we want this to be at
  449. 12:39negative six so when the pet directly
  450. 12:41behind the player is looking at the
  451. 12:43player the orientation is set to
  452. 12:44negative 90. then when the pet is on the
  453. 12:46left we add 30 degrees to this so it's a
  454. 12:48little bit more tilted towards the
  455. 12:49player and that would equal 120 and then
  456. 12:51when the pet is on the other side we
  457. 12:52need to subtract 30 degrees from the
  458. 12:54original 90 and that's why we set this
  459. 12:56to negative 60. so hopefully that gives
  460. 12:58you a good understanding of why why
  461. 12:59we're doing what we're doing then we can
  462. 13:01go ahead start the game and test out the
  463. 13:02three new positions so let's go ahead
  464. 13:04and unequip each of the pets and then
  465. 13:06let's go ahead and equip all three so we
  466. 13:08have one we have two and we have three
  467. 13:10and as we can see they're all positioned
  468. 13:11pretty nicely but we actually have to
  469. 13:13adjust this one's orientation the other
  470. 13:15two look pretty nice and as we can see
  471. 13:16we can move around with them and they're
  472. 13:18all good yes as you can see some parts
  473. 13:20of the pet are falling apart and falling
  474. 13:22off the pet when they spawn in but don't
  475. 13:23worry we'll get to that in a second so I
  476. 13:25made a mistake and I forgot to change
  477. 13:26this from negative 120 to 160 even
  478. 13:28though I just explained it now that it's
  479. 13:30at negative 60 it will be facing the
  480. 13:32correct way whenever we use that third
  481. 13:33slot so now let's go ahead and solve
  482. 13:35that issue that we had where some of the
  483. 13:36pet Parts actually fall off of the pet
  484. 13:38when we spawn the pet in the way that
  485. 13:40we're gonna do that is by going into
  486. 13:41wherever the pets are actually stored at
  487. 13:42going into their models then for each of
  488. 13:44the pets we have to select all the mesh
  489. 13:46parts that it's made of and we have to
  490. 13:48set the can Collide and can touch
  491. 13:49property to false we can also set the
  492. 13:51can Quarry so basically all the Ken
  493. 13:53properties under the Collision category
  494. 13:55we want to set those to false for all
  495. 13:56the mesh parts of each of the pets you
  496. 13:58could even turn Shadow off as well if
  497. 14:00you wanted to but you don't need to so
  498. 14:02now we're going to select all the pets
  499. 14:03and do this for every single one of
  500. 14:04their mesh parts so then once we set the
  501. 14:06properties for each of the pets we now
  502. 14:08need to actually weld the pet parts to
  503. 14:10the pet so that those parts don't fall
  504. 14:12off the pet when we spawn them in so
  505. 14:13what we need to do is we need to make
  506. 14:14sure that we understand which part is
  507. 14:16the primary part of the model and for
  508. 14:18instance we set the primary part of each
  509. 14:20of the pets to the part that has the
  510. 14:22decal inside of it so I know what the
  511. 14:24primary part is for all the pets then
  512. 14:25inside of all the other parts of the pet
  513. 14:27what we need to do is we need to
  514. 14:29actually add a weld constraint then for
  515. 14:31the weld constraint we want to set the
  516. 14:32part 0 property to the primary part of
  517. 14:34the pet so we can click part 0 and then
  518. 14:36click the primary part and then for part
  519. 14:38one we want to actually set that to the
  520. 14:40part that the weld constraint was
  521. 14:42created inside of so that part right
  522. 14:43there then what we can do is we can
  523. 14:45duplicate this well constraint by
  524. 14:46hitting Ctrl D drag it down to the part
  525. 14:48below that we don't have to touch part
  526. 14:49zero because that's already set to the
  527. 14:51primary part but what we then need to do
  528. 14:52is we then need to click on the part one
  529. 14:54and set that to the new part that we
  530. 14:56just put the weld constraint inside of
  531. 14:57so we can do that once again one once
  532. 14:59again only changing part one to the new
  533. 15:01part and then we have to do this for
  534. 15:02every single part and we have to do this
  535. 15:04for every single pet so then inside of
  536. 15:06the cat we have the well constraint
  537. 15:07let's make sure that we set part 0 to
  538. 15:09the primary part and part one to the
  539. 15:10part that the welcome train is inside of
  540. 15:12and do this for every single part all
  541. 15:14right there we go once you have all the
  542. 15:16well constraints in each of the
  543. 15:17different parts except for the primary
  544. 15:19part you're good to go and we don't have
  545. 15:21to touch the models anymore what we can
  546. 15:22actually do is we can start the game and
  547. 15:24test out that these changes have worked
  548. 15:26successfully so we can go into our game
  549. 15:27on equip a pet and equip a pet and now
  550. 15:29we can see all of the parts are actually
  551. 15:31still attached to that pet so we know
  552. 15:33that we set up the weld all correctly
  553. 15:35the next thing that we need to script up
  554. 15:36is the pet unfollowing the player
  555. 15:38whenever they unequip it so what we're
  556. 15:39going to do is create a new function
  557. 15:40above the pet follow function and this
  558. 15:42is going to be called pet unfollow and
  559. 15:44it's going to accept a player and the
  560. 15:47pet uuid which is going to be a string
  561. 15:49and inside of here we're gonna need to
  562. 15:51get the character of the player so we're
  563. 15:52going to say local character equals
  564. 15:54player dot character and we're gonna do
  565. 15:55the same thing if the character doesn't
  566. 15:57exist then we're just gonna stop the
  567. 15:58function in right there then we need to
  568. 16:00actually find the pet so we're going to
  569. 16:02create a variable called pet and we're
  570. 16:03going to set that to the character and
  571. 16:05then inside of the character we're gonna
  572. 16:06have the pets folder so we're going to
  573. 16:08say character dot pets and we use the
  574. 16:10fine first child method on this and
  575. 16:12we're going to be looking for the pet
  576. 16:14uuid because remember when we set the
  577. 16:16pet to follow the player the name of the
  578. 16:18pet is the uuiv of the pet that's why we
  579. 16:21set it to that name so we can easily
  580. 16:22find it and then we should mostly always
  581. 16:24find this pet but what we're gonna do is
  582. 16:25we're gonna say if not pet in case we
  583. 16:27don't find it for some reason then we're
  584. 16:29just gonna return n and stop the
  585. 16:30function right there otherwise if we do
  586. 16:32find the pet then we can simply destroy
  587. 16:34it so now we have that function set up
  588. 16:35all we have to do is actually call this
  589. 16:37function and we call that whenever we
  590. 16:38unequip the pet which is going to be
  591. 16:40inside of the pet equip function so
  592. 16:42right here where we unequip the pet
  593. 16:43we're going to say pet unfollow and pass
  594. 16:46through the player and the pet dot name
  595. 16:48which would be the uui beach now if we
  596. 16:50start up our game we're going to
  597. 16:51experience an error it's only happening
  598. 16:53because we're not actually setting the
  599. 16:55pets to follow the player when they join
  600. 16:56the game we're just testing out the
  601. 16:58unequipped and equipped real quick so
  602. 17:00now that we've clicked unequipped it
  603. 17:01will actually unequip the pet then we
  604. 17:03can click the unequip button again and
  605. 17:04this will equip the pet so we can see
  606. 17:06that we have the pet following us if we
  607. 17:07click on equip and unequip the pet the
  608. 17:09pet stops following us and if we click
  609. 17:10equip again we can see that it starts
  610. 17:12following us again so this is working
  611. 17:13perfectly now the other time that the
  612. 17:15pet should stop following us is whenever
  613. 17:17we actually delete the pet so we're also
  614. 17:18going to call the pet unfollow function
  615. 17:20inside of the Pet delete function as
  616. 17:22well so right before we actually destroy
  617. 17:24the pet instance what we need to do is
  618. 17:25we need to call that pet unfollow
  619. 17:27function and we're going to pass through
  620. 17:28the player and the uuid which is an
  621. 17:30argument of this function the next thing
  622. 17:32we need to do is we need to actually get
  623. 17:33the pets to follow the player whenever
  624. 17:35the player joins the game or if they
  625. 17:37respawn because whenever the player dies
  626. 17:38the character is actually affected by
  627. 17:40that so we need to make sure the pets
  628. 17:42start following the player once they
  629. 17:43respawn as well what we first have to do
  630. 17:45is we have to actually get the players
  631. 17:46served so we're just going to copy and
  632. 17:48paste that say players and create a
  633. 17:50variable for the Player's service then
  634. 17:51down here we're going to say
  635. 17:52players.player added connect function
  636. 17:55player which is a player and then since
  637. 17:57we're getting the player whenever they
  638. 17:58join the game we can listen to the
  639. 18:00character added event as well and we're
  640. 18:02going to connect that to another
  641. 18:03function and that will give us the
  642. 18:05player's character now this character
  643. 18:06added function we're actually listening
  644. 18:08to whenever the player respawns as well
  645. 18:10as when they first join the game so
  646. 18:12we've got both those scenarios covered
  647. 18:13now we have to actually get the pets to
  648. 18:15follow the player the thing is though is
  649. 18:16that when the player first spawns into
  650. 18:17the game they might not actually be
  651. 18:19parented to the workspace which is
  652. 18:21needed for our function to work so what
  653. 18:23we're going to do is we're going to
  654. 18:24create a variable called seconds and
  655. 18:26we're going to set that to zero and
  656. 18:28we're going to use a repeat Loop and
  657. 18:29what we're going to repeat is Task dot
  658. 18:32weight one so we're gonna wait one
  659. 18:33second and we're going to say seconds
  660. 18:36plus equals one so we add one to our
  661. 18:38seconds variable every second and now
  662. 18:40what we need to happen is we need for
  663. 18:41the character.parent dot name to be
  664. 18:44equal to workspace so that we know that
  665. 18:47the player is actually parented to the
  666. 18:48workspace or seconds equals 10. and if
  667. 18:52seconds equals 10 something probably bad
  668. 18:54is going on the player might be really
  669. 18:55laggy or completely disconnected from
  670. 18:57the game so we don't want this Loop to
  671. 18:59go infinitely that's why we're giving
  672. 19:00this Loop 10 seconds to run or if the
  673. 19:02character gets parented to the workspace
  674. 19:04which it had been 99 of the time so then
  675. 19:06once we know that the character is a
  676. 19:07part of the workspace what we then want
  677. 19:09to do is we actually want to spawn in
  678. 19:10all the players equipped pets now how do
  679. 19:13we get all the players equipped pets
  680. 19:14well remember all the pets are stored
  681. 19:16with inside of the Pet's inventory
  682. 19:17folder so we're gonna say local pets
  683. 19:19floater equals player find first child
  684. 19:22pet inventory now that we have that
  685. 19:24folder we can go ahead and loop through
  686. 19:26it so we're going to say four underscore
  687. 19:27pet in I pairs pets folder get children
  688. 19:31do then we're gonna check if the pet is
  689. 19:33equipped so if pet dot equipped dot
  690. 19:36value then and we can then call the pet
  691. 19:38follow function on the player and pass
  692. 19:41through the pet instance as well so now
  693. 19:42let's go ahead start the game and test
  694. 19:44this out so we can see as soon as we
  695. 19:45spawn into our game all of our pets are
  696. 19:48actually equipped which should be then
  697. 19:49if we want to we can go inside of here
  698. 19:50equip another pet and we can see that
  699. 19:52pet is positioned perfectly they all
  700. 19:54follow us and everything's all good then
  701. 19:55what we can do is we can reset the
  702. 19:57character so we kill the character and
  703. 19:58whenever the character respawns we can
  704. 20:00see that all the pets are equipped once
  705. 20:02again meaning this is all working
  706. 20:04perfectly so ladies and gentlemen the
  707. 20:06pet follower system is complete and
  708. 20:07hopefully this video did help you guys
  709. 20:08out if it did make sure you smash like
  710. 20:10button also subscribe button and turn
  711. 20:11the post notifications on if you want to
  712. 20:13get notified why not blow more Roblox
  713. 20:14development content additionally I have
  714. 20:16a patreon if you guys like the support
  715. 20:17me and gain access to all the scripts
  716. 20:18and the game file that I made during
  717. 20:20this episode there's a link Down Below
  718. 20:21in the description and you guys can go
  719. 20:22and check that out with that being said
  720. 20:23I'll see you guys in the next episode
  721. 20:27all right

About this transcript

This page contains the full transcript of Scripting the Pet Follow System! Roblox Studio Simulator Guide Episode 28 by MonzterDEV, generated from the public captions YouTube serves with the video. The transcript has 5,522 words across 721 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.