Scripting the Pet Follow System! Roblox Studio Simulator Guide Episode 28 — Transcript
Full transcript
- 0:00what's going on ladies gentlemen in this
- 0:01episode of the simulator series we are
- 0:03going to be creating the pet follow
- 0:04system and as always if you guys do
- 0:06enjoy the video or it does help you out
- 0:07make sure you smash like button also
- 0:08subscribe button and turn US Post
- 0:09notifications on if you want to get
- 0:11notified want to upload more of Roblox
- 0:12moment content additionally I have a
- 0:14patreon if you guys like to support me
- 0:15and gain access to all the scripts and
- 0:16the game file that I've made in this
- 0:18episode there's a link Down Below in the
- 0:19description and you guys can go and
- 0:20check that out with that being said
- 0:21let's get right into it so happen
- 0:22directly and eating simulator to see
- 0:24their pet follow system whenever we
- 0:26spawn in all of our pets that we have
- 0:27equipped spawn in with us and they do
- 0:29begin to follow us their rotation also
- 0:31does change depending on what our
- 0:32rotation currently is and if we go
- 0:34inside of our pet inventory and we equip
- 0:36a new pet we can see that pet is now
- 0:38following us as well and positioned
- 0:39correctly additionally if we unequip a
- 0:41pet the pet is no longer following us
- 0:43the same also goes if we delete a pet
- 0:45that's currently following us as well
- 0:46that pet will stop following us so now
- 0:48if the system explained let's hop
- 0:49directly in a Roblox studio so once we
- 0:51get into Roblox Studio the first thing
- 0:52we want to do is we want to go to the
- 0:53server script service and look inside of
- 0:55the pet script now inside of the script
- 0:57we're going to create a brand new
- 0:58function towards the top of our our
- 1:00script and that is going to be called
- 1:01pet follow-up now this function is going
- 1:03to accept a player and the pet which is
- 1:05actually going to be an instance this
- 1:07instance is actually going to be the
- 1:08folder that's stored inside of the
- 1:09player's pet inventory which includes
- 1:11all the information about the pet now
- 1:13the first thing we want to do inside of
- 1:14this function is we want to actually
- 1:15find the player's character and the way
- 1:17that we're going to do that is by just
- 1:18saying player dot character now we need
- 1:20to check if this character is actually
- 1:22existing so we're going to say if not
- 1:24character then return end so stop the
- 1:27function right there if the character
- 1:28does not exist and now the next thing we
- 1:30need to do is we need to either create a
- 1:32folder or check if the folder already
- 1:34exists inside of the player's character
- 1:36for where we're going to be storing the
- 1:37pet models that are going to be
- 1:38following the player so we're going to
- 1:40say local pets folder equals character
- 1:42find first child pets and that's going
- 1:45to be the name of the folder and then
- 1:46what we want to do is we want to say if
- 1:48not pets folder so if that folder was
- 1:50not found then what we want to do is we
- 1:51want to actually create the folder so
- 1:53we're going to say pets folder equals
- 1:55instance dot new and we're going to
- 1:57create a brand new folder and we're
- 1:58going to parent that to the players
- 1:59character then we're gonna set the name
- 2:01of this folder to pets and there we go
- 2:03we've now created the folder and we'll
- 2:04only ever create this one time after
- 2:06that the pets folder will be set right
- 2:08here because we will be able to find
- 2:09that folder within the character then
- 2:10the next thing we need to do is we need
- 2:12to actually get the model of the pet
- 2:13that we have stored with inside of the
- 2:16replicated storage and inside of the
- 2:17Pet's folder so we're going to say local
- 2:19pet model equals replicate storage dot
- 2:22pets find first child pet and now
- 2:24remember this is the instance that we
- 2:26created in the last episode if you guys
- 2:27are a little bit confused about that we
- 2:28can go inside of the utils folder and
- 2:30inside of the rewards module and inside
- 2:32of here this is one of the areas where
- 2:33we actually create this folder so we
- 2:34have a folder the name of that folder is
- 2:36the uuid of the pet and then inside of
- 2:38that folder there are two string values
- 2:39and one bull value and the string value
- 2:41that we're going to be using right now
- 2:42is the ID now I'm only showing you guys
- 2:44this to give you a reference back to the
- 2:45last episode when we actually created
- 2:47this so hopefully you guys are not
- 2:48confused at all by what we're indexing
- 2:50or what we're getting when we actually
- 2:51look inside of the pet instance so we're
- 2:54gonna say pet thought ID to get the
- 2:55string value and then we want to get the
- 2:56value of that ID because that will tell
- 2:58us a specific pet that we're looking for
- 3:00and then once we actually find that
- 3:02model what we then want to do is we want
- 3:03to clone it now that we have a clone of
- 3:05the pet model what we then want to do is
- 3:06we want to set the position of the pet
- 3:08to the player's character and now we're
- 3:10not getting the correct Auto completion
- 3:11right here so what I'm going to do is
- 3:12I'm going to actually annotate the type
- 3:14of this pet model to a model to tell
- 3:16Studio that it is a model which it will
- 3:18be so then we can just type in p and now
- 3:20we see the pivot 2 method so we can use
- 3:22that and now the Target c-frame that we
- 3:24want to use is the character that
- 3:25humanoid root part make sure all the
- 3:28capitalizations are correct and then dot
- 3:30C frame so now we set the position of
- 3:32the pet to the player what we're now
- 3:33going to do is basically create the
- 3:34opponents which will move and rotate the
- 3:36pet around the player whenever the
- 3:38player moves so we're going to create an
- 3:39attachment and we're going to attach
- 3:41this to the character's humanoid root
- 3:43part so we're going to say local
- 3:44character attachment equals instance dot
- 3:48new attachment and we're going to parent
- 3:49that to the character.humanoid root part
- 3:52and we want to set this attachment
- 3:54visibility to false so that we don't
- 3:56actually see that now we're going to
- 3:57actually create another attachment and
- 3:58this time we're actually going going to
- 4:00attach that to the pet model's primary
- 4:02part so what we can do is we can
- 4:03literally copy what we just did and
- 4:05rename this from character attachment to
- 4:07pet attachment and of course we want to
- 4:08copy that variable down here and now
- 4:10when we set the parent once again we
- 4:12want to set the parent to the pet model
- 4:13dot primary part and the visibility is
- 4:16going to be false for this as well next
- 4:17we want to actually create an align
- 4:19position so we're going to say local
- 4:20align position equals instance dot new
- 4:24align position and this is going to be
- 4:26parented to the pet model then we have
- 4:28to set a couple of different properties
- 4:29of the Align position so the first one
- 4:30that we want to set is the max force and
- 4:32we're going to set this to 25
- 4:34000 and then we actually need to set
- 4:36both the attachment properties to the
- 4:38attachments that we just created so
- 4:39we're going to say line position dot
- 4:40attachment zero and we're going to set
- 4:42that to the pet attachment and then for
- 4:44the attachment one we're gonna set that
- 4:45to the character attachment then we want
- 4:47to set the responsiveness of the Align
- 4:49position and we're going to set that to
- 4:5125. now we're done with the Align
- 4:52position for right now the next thing
- 4:53that we need to create is the Align
- 4:55orientation so we're going to say local
- 4:56align orientation equals instance dot
- 5:00new align orientation and once again
- 5:02that's going to be parented to the Pet
- 5:04Mount now we need to set some properties
- 5:05for this similar to the ones that we
- 5:06just set for the Align position so for
- 5:08the Align orientation we're going to set
- 5:10the max torque and that's also going to
- 5:12be set to 25 000 and then once again we
- 5:14need to set the attachment for this as
- 5:15well so we're going to say a line
- 5:16orientation dot attachment zero equals
- 5:19pet attachment and then align
- 5:21orientation dot attachment one equals
- 5:24character attachment and then finally we
- 5:26need to set the responsiveness of this
- 5:27and that's also going to be to 25 as
- 5:29well the next thing that we're going to
- 5:30do is we're going to create an INT value
- 5:32which is going to hold a number based on
- 5:34the order that the pet was equipped now
- 5:36the reason that we're going to do this
- 5:37is because imagine that you're equipping
- 5:38a couple of different pets depending on
- 5:40how many pets you have equipped you need
- 5:42to position each of the pets in a
- 5:44different position to prevent them all
- 5:45from being within the same exact
- 5:47position so we can say local order
- 5:49equals instance dot new int value and
- 5:52parent that to the pet model and we're
- 5:53going to set the name of this in value
- 5:54to order now to set the value of the
- 5:57order we actually need to create a
- 5:58function so that we can figure out out
- 6:00what number we want to set this Pet's
- 6:02order to so above the pet follow
- 6:03function we're going to create a new
- 6:05function and that's going to be called
- 6:06get pet order and all we need is a
- 6:09character which is of course going to be
- 6:10a model the first thing that we're going
- 6:12to do is we're going to create a
- 6:12variable for the pets folder and we're
- 6:14going to set that equal to character dot
- 6:16pets now that we have the pets voter
- 6:18what we first want to do is we want to
- 6:19check if there are any pets currently
- 6:21with inside of this folder if there are
- 6:23no pets inside of this folder then we
- 6:24know automatically that the order should
- 6:26be one because that would be the first
- 6:27pet going into this folder the way that
- 6:29we can do this is we can say if hashtag
- 6:31pet folder get children equals zero then
- 6:34return one so if there are zero children
- 6:36with inside of the pets folder then
- 6:38we're going to return one as the order
- 6:39now if there are children inside this
- 6:41folder the next thing we want to do is
- 6:42we want to create a variable for all of
- 6:44the active slots which are currently
- 6:46taken up then what we're going to do is
- 6:47we're going to Loop through all the pets
- 6:48inside of the pet folder so we're going
- 6:50to say pet folder get children do then
- 6:52we're gonna get the order of the pet so
- 6:54we're gonna say local order equals pet
- 6:56dot order dot value because remember we
- 6:58just created that down here we haven't
- 7:00set the value yet but we're going to set
- 7:01the value based off this function so
- 7:02don't worry about that that value will
- 7:04exist and then we want to use the order
- 7:06that we just got to set the active slots
- 7:08so we're going to say active slots order
- 7:10equals order so we're now tracking each
- 7:12of the orders and putting them inside of
- 7:14the active slots table then the next
- 7:15thing we want to do is we want to create
- 7:16another for Loop and we're going to say
- 7:18four available slot and this is going to
- 7:21be set to one I know it's really weird
- 7:22using the standard for Loop but that's
- 7:24we're going to be using for this then we
- 7:25have to identify the max amount of Loops
- 7:27that this for Loop can actually go
- 7:28through so this should realistically be
- 7:30the max amount of pets that a player can
- 7:31actually have equipped and I'm just
- 7:32going to set it to five for this example
- 7:34then we have to indicate how much we
- 7:35want to increase available slot by each
- 7:38Loop and we're going to say one then
- 7:39we'll say do and now we have our for
- 7:41Loop created then we want to do is we
- 7:42want to check if the active slot
- 7:44contains the available slot which would
- 7:46be a number so in the first Loop it
- 7:48would be one then two then three then
- 7:50four and then go all the way up to five
- 7:51and then the first number that active
- 7:53slots does not contain we are going to
- 7:55return that available slot so we're
- 7:57going to return that number and we need
- 7:59to make sure that we say not active slot
- 8:00because we're looking to see if it
- 8:02doesn't exist so now imagine if inside
- 8:03of active slots the numbers are one and
- 8:06three inside of this for loop it's gonna
- 8:07go through the first Loop and it's gonna
- 8:08say okay one exists so we're not going
- 8:10to do anything then it's going to check
- 8:11if two exists inside of active slot it's
- 8:14going to see that two does not exist so
- 8:15that slot is free and then it's going to
- 8:17return two so then we know that we're
- 8:18going to set the order value of this pet
- 8:20to that number so then we can come back
- 8:22down to the pet follow function and
- 8:23underneath where we set the name of the
- 8:25order instance we can also set the value
- 8:26as well and we're going to set that to
- 8:28get pet order and all we have to do is
- 8:30pass through the player's character so
- 8:32after we get the order we actually have
- 8:33to set the position of the pet now what
- 8:35we're going to do is above the get order
- 8:36function we're actually going to create
- 8:38a new table and it's going to be called
- 8:39pet positions now this table is actually
- 8:41going to be array which is going to hold
- 8:43more tables the tables inside of here
- 8:45are going to have two properties the
- 8:46position property and this is actually
- 8:48going to hold the position of where the
- 8:49pet should be and the position is going
- 8:51to be a vector three and for the first
- 8:52position we most likely want the pet
- 8:54directly behind the player so we're
- 8:55gonna say zero comma one comma 10 and
- 8:58then the other property that this table
- 8:59is going hold is orientation and we're
- 9:01going to set that to once again a vector
- 9:03three and this is going to be 0 negative
- 9:0590 0. and now the orientation is the way
- 9:07that the pet is facing and of course the
- 9:09position is how far the pet is gonna be
- 9:11from The Plight and we will create more
- 9:13of these so that each pet that we have
- 9:14equipped can have its own position but
- 9:16for now we'll go back to the pet
- 9:17function and we'll actually set the
- 9:18Pet's position so we're gonna say local
- 9:19pet position and we're gonna get that
- 9:21from the pet positions table that we
- 9:22just created and we're actually gonna
- 9:24Index this table with the order dot
- 9:27value that we just set so now once we
- 9:28have the specific pets position what
- 9:30we're then going to do is we're going to
- 9:31set the character's attachment that
- 9:33position to the pet positions dot
- 9:35position and then we're also going to
- 9:37set the character attachment.orientation
- 9:39to the pet
- 9:41positions.orientation and now make sure
- 9:43that you're setting it to the variable
- 9:44that we just created and not to the
- 9:46table that we just created which is what
- 9:47I did so now that is set up correctly
- 9:49then finally what we're gonna do is we
- 9:51need to set the pet model dot name to
- 9:54the actual uuid of the pet so that we
- 9:56can easily find it in case we want to
- 9:58destroy it and now remember the uuid
- 10:00would be the name of this pet so we're
- 10:01going to say pet dot name and then we
- 10:03also need to set the parent of the model
- 10:05as well so petmodel dot parent equals
- 10:07the pet folder that we just created and
- 10:09then lastly we need to set the network
- 10:10ownership of this pet so we're going to
- 10:12say petmodel dot primary part set
- 10:15network owner and we're going to set
- 10:17that to the player okay so we now have
- 10:18the pet follow function basically
- 10:20created then we actually need to call
- 10:21this function and when are we going to
- 10:22call this function well whenever we
- 10:24actually equip a pet which we have a
- 10:25comment laid out right here for us so
- 10:27we're going to say pet follow and we'll
- 10:29pass through the player and the pet
- 10:30instance now let's go ahead and start
- 10:32the game and test this function out so
- 10:33now when we hop into our game let's go
- 10:35ahead and equip this cat pet and we can
- 10:36see that the pet actually does appear
- 10:38behind us and it is following us so we
- 10:40can tell that this is working perfectly
- 10:42so now that we know that this pet is
- 10:43following us successfully the next thing
- 10:45we need to actually do is set up more
- 10:46pet positions so that we can equip more
- 10:48pets so going back to the pet positions
- 10:50let's talk about the position currently
- 10:52now if you're unaware of how Vector
- 10:53threes work this is the X this is the Y
- 10:55and this is the Z the Y usually
- 10:57indicates up and down the action usually
- 11:00indicates left or right and then the Z
- 11:01usually indicates basically forward or
- 11:04behind the character so the reason that
- 11:05this is that 10 is because this means
- 11:07that the pet appears 10 studs behind the
- 11:09player if we set this to five then the
- 11:11pet would actually appear five studs
- 11:13behind the player so this would be
- 11:14closer to the player now if we want to
- 11:16make the pet higher up off of the ground
- 11:17and higher above the player we could set
- 11:19this to five and they would probably be
- 11:21much higher than the player currently is
- 11:22so now that we understand how the
- 11:24position Works let's talk about the
- 11:25orientation the orientation is what the
- 11:27pet is currently facing and we figured
- 11:29out that the Y value of the vector 3
- 11:31basically makes the pet look left or
- 11:33right and the reason that we have the
- 11:34orientation set to negative 90 degrees
- 11:36is because we have the pet behind the
- 11:38players so we need to set the
- 11:39orientation for the pet to be facing the
- 11:42player now you can easily modify these
- 11:43numbers to work with it yourself and
- 11:45learn more about the orientation and the
- 11:46position but I have a list of my own
- 11:48preset positions and orientations which
- 11:50will work so that's what we're going to
- 11:51use for now so for the second position
- 11:53we can just copy and paste this and now
- 11:55all we have to do is modify a little bit
- 11:56of the position and the orientation so
- 11:58for the second and the third pet we most
- 12:00likely want those to appear behind the
- 12:01player as well one to the left and one
- 12:03to the right so when the player has all
- 12:05three pets equipped one is directly
- 12:06behind them and one is to the left and
- 12:08the right behind them as well so for
- 12:10this to work we are going to set the x
- 12:12to negative 7.5 the Y is going to stay
- 12:14the same the Z is actually going to be a
- 12:16little bit smaller and this is going to
- 12:17be set to eight then we also need to
- 12:19change the rotation a little bit because
- 12:20we need it to be rotated a little bit
- 12:22more so we're going to set that to
- 12:23negative 120. then for the third
- 12:25position we want this pet to be on the
- 12:27other side so like let's say for
- 12:28instance if the second position is on
- 12:30the left of the player we want this to
- 12:31be on the right of the player so instead
- 12:33of saying negative 7.5 we can actually
- 12:35set this to a positive 7.5 and then for
- 12:37the orientation we want this to be at
- 12:39negative six so when the pet directly
- 12:41behind the player is looking at the
- 12:43player the orientation is set to
- 12:44negative 90. then when the pet is on the
- 12:46left we add 30 degrees to this so it's a
- 12:48little bit more tilted towards the
- 12:49player and that would equal 120 and then
- 12:51when the pet is on the other side we
- 12:52need to subtract 30 degrees from the
- 12:54original 90 and that's why we set this
- 12:56to negative 60. so hopefully that gives
- 12:58you a good understanding of why why
- 12:59we're doing what we're doing then we can
- 13:01go ahead start the game and test out the
- 13:02three new positions so let's go ahead
- 13:04and unequip each of the pets and then
- 13:06let's go ahead and equip all three so we
- 13:08have one we have two and we have three
- 13:10and as we can see they're all positioned
- 13:11pretty nicely but we actually have to
- 13:13adjust this one's orientation the other
- 13:15two look pretty nice and as we can see
- 13:16we can move around with them and they're
- 13:18all good yes as you can see some parts
- 13:20of the pet are falling apart and falling
- 13:22off the pet when they spawn in but don't
- 13:23worry we'll get to that in a second so I
- 13:25made a mistake and I forgot to change
- 13:26this from negative 120 to 160 even
- 13:28though I just explained it now that it's
- 13:30at negative 60 it will be facing the
- 13:32correct way whenever we use that third
- 13:33slot so now let's go ahead and solve
- 13:35that issue that we had where some of the
- 13:36pet Parts actually fall off of the pet
- 13:38when we spawn the pet in the way that
- 13:40we're gonna do that is by going into
- 13:41wherever the pets are actually stored at
- 13:42going into their models then for each of
- 13:44the pets we have to select all the mesh
- 13:46parts that it's made of and we have to
- 13:48set the can Collide and can touch
- 13:49property to false we can also set the
- 13:51can Quarry so basically all the Ken
- 13:53properties under the Collision category
- 13:55we want to set those to false for all
- 13:56the mesh parts of each of the pets you
- 13:58could even turn Shadow off as well if
- 14:00you wanted to but you don't need to so
- 14:02now we're going to select all the pets
- 14:03and do this for every single one of
- 14:04their mesh parts so then once we set the
- 14:06properties for each of the pets we now
- 14:08need to actually weld the pet parts to
- 14:10the pet so that those parts don't fall
- 14:12off the pet when we spawn them in so
- 14:13what we need to do is we need to make
- 14:14sure that we understand which part is
- 14:16the primary part of the model and for
- 14:18instance we set the primary part of each
- 14:20of the pets to the part that has the
- 14:22decal inside of it so I know what the
- 14:24primary part is for all the pets then
- 14:25inside of all the other parts of the pet
- 14:27what we need to do is we need to
- 14:29actually add a weld constraint then for
- 14:31the weld constraint we want to set the
- 14:32part 0 property to the primary part of
- 14:34the pet so we can click part 0 and then
- 14:36click the primary part and then for part
- 14:38one we want to actually set that to the
- 14:40part that the weld constraint was
- 14:42created inside of so that part right
- 14:43there then what we can do is we can
- 14:45duplicate this well constraint by
- 14:46hitting Ctrl D drag it down to the part
- 14:48below that we don't have to touch part
- 14:49zero because that's already set to the
- 14:51primary part but what we then need to do
- 14:52is we then need to click on the part one
- 14:54and set that to the new part that we
- 14:56just put the weld constraint inside of
- 14:57so we can do that once again one once
- 14:59again only changing part one to the new
- 15:01part and then we have to do this for
- 15:02every single part and we have to do this
- 15:04for every single pet so then inside of
- 15:06the cat we have the well constraint
- 15:07let's make sure that we set part 0 to
- 15:09the primary part and part one to the
- 15:10part that the welcome train is inside of
- 15:12and do this for every single part all
- 15:14right there we go once you have all the
- 15:16well constraints in each of the
- 15:17different parts except for the primary
- 15:19part you're good to go and we don't have
- 15:21to touch the models anymore what we can
- 15:22actually do is we can start the game and
- 15:24test out that these changes have worked
- 15:26successfully so we can go into our game
- 15:27on equip a pet and equip a pet and now
- 15:29we can see all of the parts are actually
- 15:31still attached to that pet so we know
- 15:33that we set up the weld all correctly
- 15:35the next thing that we need to script up
- 15:36is the pet unfollowing the player
- 15:38whenever they unequip it so what we're
- 15:39going to do is create a new function
- 15:40above the pet follow function and this
- 15:42is going to be called pet unfollow and
- 15:44it's going to accept a player and the
- 15:47pet uuid which is going to be a string
- 15:49and inside of here we're gonna need to
- 15:51get the character of the player so we're
- 15:52going to say local character equals
- 15:54player dot character and we're gonna do
- 15:55the same thing if the character doesn't
- 15:57exist then we're just gonna stop the
- 15:58function in right there then we need to
- 16:00actually find the pet so we're going to
- 16:02create a variable called pet and we're
- 16:03going to set that to the character and
- 16:05then inside of the character we're gonna
- 16:06have the pets folder so we're going to
- 16:08say character dot pets and we use the
- 16:10fine first child method on this and
- 16:12we're going to be looking for the pet
- 16:14uuid because remember when we set the
- 16:16pet to follow the player the name of the
- 16:18pet is the uuiv of the pet that's why we
- 16:21set it to that name so we can easily
- 16:22find it and then we should mostly always
- 16:24find this pet but what we're gonna do is
- 16:25we're gonna say if not pet in case we
- 16:27don't find it for some reason then we're
- 16:29just gonna return n and stop the
- 16:30function right there otherwise if we do
- 16:32find the pet then we can simply destroy
- 16:34it so now we have that function set up
- 16:35all we have to do is actually call this
- 16:37function and we call that whenever we
- 16:38unequip the pet which is going to be
- 16:40inside of the pet equip function so
- 16:42right here where we unequip the pet
- 16:43we're going to say pet unfollow and pass
- 16:46through the player and the pet dot name
- 16:48which would be the uui beach now if we
- 16:50start up our game we're going to
- 16:51experience an error it's only happening
- 16:53because we're not actually setting the
- 16:55pets to follow the player when they join
- 16:56the game we're just testing out the
- 16:58unequipped and equipped real quick so
- 17:00now that we've clicked unequipped it
- 17:01will actually unequip the pet then we
- 17:03can click the unequip button again and
- 17:04this will equip the pet so we can see
- 17:06that we have the pet following us if we
- 17:07click on equip and unequip the pet the
- 17:09pet stops following us and if we click
- 17:10equip again we can see that it starts
- 17:12following us again so this is working
- 17:13perfectly now the other time that the
- 17:15pet should stop following us is whenever
- 17:17we actually delete the pet so we're also
- 17:18going to call the pet unfollow function
- 17:20inside of the Pet delete function as
- 17:22well so right before we actually destroy
- 17:24the pet instance what we need to do is
- 17:25we need to call that pet unfollow
- 17:27function and we're going to pass through
- 17:28the player and the uuid which is an
- 17:30argument of this function the next thing
- 17:32we need to do is we need to actually get
- 17:33the pets to follow the player whenever
- 17:35the player joins the game or if they
- 17:37respawn because whenever the player dies
- 17:38the character is actually affected by
- 17:40that so we need to make sure the pets
- 17:42start following the player once they
- 17:43respawn as well what we first have to do
- 17:45is we have to actually get the players
- 17:46served so we're just going to copy and
- 17:48paste that say players and create a
- 17:50variable for the Player's service then
- 17:51down here we're going to say
- 17:52players.player added connect function
- 17:55player which is a player and then since
- 17:57we're getting the player whenever they
- 17:58join the game we can listen to the
- 18:00character added event as well and we're
- 18:02going to connect that to another
- 18:03function and that will give us the
- 18:05player's character now this character
- 18:06added function we're actually listening
- 18:08to whenever the player respawns as well
- 18:10as when they first join the game so
- 18:12we've got both those scenarios covered
- 18:13now we have to actually get the pets to
- 18:15follow the player the thing is though is
- 18:16that when the player first spawns into
- 18:17the game they might not actually be
- 18:19parented to the workspace which is
- 18:21needed for our function to work so what
- 18:23we're going to do is we're going to
- 18:24create a variable called seconds and
- 18:26we're going to set that to zero and
- 18:28we're going to use a repeat Loop and
- 18:29what we're going to repeat is Task dot
- 18:32weight one so we're gonna wait one
- 18:33second and we're going to say seconds
- 18:36plus equals one so we add one to our
- 18:38seconds variable every second and now
- 18:40what we need to happen is we need for
- 18:41the character.parent dot name to be
- 18:44equal to workspace so that we know that
- 18:47the player is actually parented to the
- 18:48workspace or seconds equals 10. and if
- 18:52seconds equals 10 something probably bad
- 18:54is going on the player might be really
- 18:55laggy or completely disconnected from
- 18:57the game so we don't want this Loop to
- 18:59go infinitely that's why we're giving
- 19:00this Loop 10 seconds to run or if the
- 19:02character gets parented to the workspace
- 19:04which it had been 99 of the time so then
- 19:06once we know that the character is a
- 19:07part of the workspace what we then want
- 19:09to do is we actually want to spawn in
- 19:10all the players equipped pets now how do
- 19:13we get all the players equipped pets
- 19:14well remember all the pets are stored
- 19:16with inside of the Pet's inventory
- 19:17folder so we're gonna say local pets
- 19:19floater equals player find first child
- 19:22pet inventory now that we have that
- 19:24folder we can go ahead and loop through
- 19:26it so we're going to say four underscore
- 19:27pet in I pairs pets folder get children
- 19:31do then we're gonna check if the pet is
- 19:33equipped so if pet dot equipped dot
- 19:36value then and we can then call the pet
- 19:38follow function on the player and pass
- 19:41through the pet instance as well so now
- 19:42let's go ahead start the game and test
- 19:44this out so we can see as soon as we
- 19:45spawn into our game all of our pets are
- 19:48actually equipped which should be then
- 19:49if we want to we can go inside of here
- 19:50equip another pet and we can see that
- 19:52pet is positioned perfectly they all
- 19:54follow us and everything's all good then
- 19:55what we can do is we can reset the
- 19:57character so we kill the character and
- 19:58whenever the character respawns we can
- 20:00see that all the pets are equipped once
- 20:02again meaning this is all working
- 20:04perfectly so ladies and gentlemen the
- 20:06pet follower system is complete and
- 20:07hopefully this video did help you guys
- 20:08out if it did make sure you smash like
- 20:10button also subscribe button and turn
- 20:11the post notifications on if you want to
- 20:13get notified why not blow more Roblox
- 20:14development content additionally I have
- 20:16a patreon if you guys like the support
- 20:17me and gain access to all the scripts
- 20:18and the game file that I made during
- 20:20this episode there's a link Down Below
- 20:21in the description and you guys can go
- 20:22and check that out with that being said
- 20:23I'll see you guys in the next episode
- 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.