Teleport Service (Teleporting, Servers, Send Data) - Roblox Advanced Scripting #26 — Transcript
Full transcript
- 0:00damn I can't even play this game until I
- 0:02have another person inside of this pad
- 0:04for this matchmaking system oh my God
- 0:07what am I going to do about this oh wait
- 0:09wait I see a player hey you bro over
- 0:11there huh yeah I'm talking to you bro
- 0:13come over here I need another person so
- 0:15that we can actually play this game all
- 0:17right we got two out of two players so
- 0:18now let's see oh all right we're going
- 0:20into the next game oo let's see what
- 0:23this game is about to be
- 0:25like
- 0:26uh what am I in hell right now
- 0:30bro this is kind of weird is this what
- 0:33Roblox games be like nowadays oh my
- 0:36goodness this is um this is quite an
- 0:38interesting place both of us landed into
- 0:40all right but what you just saw was a
- 0:42teleportation from the main game that we
- 0:44were just playing on to this other
- 0:46alternative game that's really strange
- 0:49but uh that is essentially what happened
- 0:51we got into a Teleport matchmaking
- 0:53system and then we got teleported to
- 0:54another place within the same exact game
- 0:57and this is using a feature called
- 0:59teleport service that essentially allows
- 1:01us to teleport players between places
- 1:05within the same game and do other cool
- 1:07neat features with it like sending data
- 1:09over uh to other servers and joining
- 1:11specific players into specific servers
- 1:13and things like that so in this video
- 1:15I'm going to be showing you how teleport
- 1:17service works and how you can implement
- 1:18it inside of Roblox Studio but let me
- 1:21try and explain more of teleport service
- 1:24before we get into implementing so let's
- 1:26go straight into that all right let's
- 1:28think about this for a minute I'm going
- 1:29to try and explain the concept of
- 1:31teleport service so that we can get a
- 1:33better idea of how this works and why
- 1:35it's important for us to know uh how to
- 1:38use this inside of Roblox studio so with
- 1:40the example that I showed you in the
- 1:41beginning of this video we had a
- 1:43matchmaking system over there and once
- 1:45we had enough players we were teleported
- 1:48to a different place within the same
- 1:50game that had its own contents that was
- 1:53not available inside of this main game
- 1:55right here um and this is using uh the
- 1:58ability that we have as developers to
- 2:01teleport players into a different place
- 2:03within the same game and so the way I
- 2:05want you to think about this is if I
- 2:07were to open up Explorer we have
- 2:09everything inside of here that comprises
- 2:11of a game with its own properties and
- 2:14things like that so what you're seeing
- 2:15right now is the main game but if we
- 2:17were to teleport to a different place
- 2:20then this uh game would basically be
- 2:22reset back to its defaults and we can
- 2:25add whatever we want um inside of this
- 2:28game that's going to be different from
- 2:30this main game and so that's how I want
- 2:33you to think about this in terms of
- 2:34different places within the same game
- 2:37and so now I want to show you what this
- 2:38looks like conceptually so what we have
- 2:42going on here is the game itself and
- 2:45this game can be comprised of multiple
- 2:48different places attached to the same
- 2:50game so uh as we've been following along
- 2:53through this Advanced scripting tutorial
- 2:54guide we've basically just been having
- 2:56one place be connected to the game and
- 2:59so so with the ability of teleport
- 3:01service we can create as many places as
- 3:04we want attached to the game itself so
- 3:08what I want you to understand is there
- 3:10can only be one game but there can be
- 3:13multiple games attached to the same game
- 3:15if we want to teleport players between
- 3:18each of these places and so now I want
- 3:20you to understand how creating servers
- 3:22work inside of this structure so how how
- 3:26do servers work when players join into
- 3:29the game we need to be able to create a
- 3:31server for them to be able to join into
- 3:32this game as you probably know so what
- 3:35Roblox decides to do is create a public
- 3:38server uh that's open to anybody who
- 3:40joins into the game to then be thrown
- 3:42into this public server as long as
- 3:45there's enough players that um don't
- 3:47reach Max Capacity or whatever so uh the
- 3:50players once they join to the game they
- 3:52join into the main place now if let's
- 3:54say we wanted to have the players join
- 3:56into another place like if we were to
- 3:58teleport them to the second place we
- 4:00need Roblox to create another public
- 4:02server so that these players can be
- 4:05teleported over to This Server inside of
- 4:08the second place so we're going to use
- 4:09teleport service to essentially move the
- 4:12players from this game or from this
- 4:14place into this place over here and if
- 4:17let's say we teleported everybody then
- 4:19we then this is just going to be an
- 4:20empty server and Roblox can just remove
- 4:23this public server because we don't need
- 4:24it anymore and so this is essentially
- 4:27how server hopping or server
- 4:28teleportation works inside of Roblox
- 4:31Studio within different places and we
- 4:33can basically just do the same thing
- 4:34with Place three as well if we created a
- 4:36public server then we can uh send the
- 4:38players over to this place and you kind
- 4:40of get the idea at this point so that is
- 4:43how server teleportation works but what
- 4:45makes this interesting is that we can
- 4:47have different server types for players
- 4:50to teleport into this game so uh another
- 4:54type of server that's interesting to
- 4:55know about is reserved servers and with
- 4:59the name reserved servers basically what
- 5:01this is is if we let's say had players
- 5:04uh back from the main place like this uh
- 5:07if we wanted to teleport them to an
- 5:10exclusive server inside of this place so
- 5:12that if future players came into the
- 5:15main game and wanted to teleport to this
- 5:17place then they would not be able to be
- 5:19uh joining inside of this Reserve server
- 5:22because this is only exclusive to the
- 5:24players that were sent over to this
- 5:26place uh from the beginning so if we
- 5:28sent the players over to this reserved
- 5:30server then no players up until this
- 5:33point like if let's say we had more
- 5:35players here they cannot Join This
- 5:37Server because this is a reserved server
- 5:39they can only go to the public server um
- 5:42that is created for them inside of place
- 5:44two or if we created a new Reserve
- 5:47server for these players to play inside
- 5:49of the game I hope this is making sense
- 5:50to you uh this is basically the idea of
- 5:54how teleportation Works inside of a game
- 5:56within different places um there can
- 5:58also be other things things like sending
- 6:00data over between different places but
- 6:03I'm going to go more into detail of what
- 6:05this entails later on inside of the
- 6:06video and that is essentially the basic
- 6:08structure of this now with teleport
- 6:10service you can even teleport to uh
- 6:13thirdparty games that are not included
- 6:15within your game itself like let's say
- 6:18we had another game here with adopt me
- 6:20or another game with pet Simulator X
- 6:22then we can send the player from our
- 6:24game to that uh like alternative third
- 6:28party game as well with teleport servers
- 6:29but for the sake of this tutorial I'm
- 6:31going to resort to just teleporting
- 6:34between different places within the same
- 6:36game that we own so I hope this has made
- 6:38sense to you and with that being said
- 6:40let's go ahead and get straight into
- 6:42implementing teleport service inside of
- 6:44Roblox studio now that we understand it
- 6:47let's Implement teleport service inside
- 6:49of Roblox studio now as I explained
- 6:51earlier we need to be able to have
- 6:53multiple places within the game so that
- 6:55we can teleport these players between
- 6:57these places because by default when you
- 7:00create a a game on Roblox um there's
- 7:03only one place attached to it which is
- 7:05just this main game right here but now
- 7:07we have the ability to create multiple
- 7:09places that connect to the exact same
- 7:11game and the way we do that is by going
- 7:14up to view and we're going to be
- 7:16clicking on asset manager over here and
- 7:18there's going to be a bunch of these
- 7:20folders here that we can create as
- 7:22assets to be used inside of our game and
- 7:24the first one on the list is places so
- 7:26we're going to double click on this and
- 7:28there should be a a list of all the
- 7:30games or all the places that we have
- 7:32contained within this game so what we're
- 7:34going to do is create a place within
- 7:37this game right here so we're going to
- 7:39Simply right click on this and we're
- 7:40going to hit add new place like this and
- 7:43so Roblox is going to generate a new
- 7:45place for us that's now attached to this
- 7:47game that we're playing so if we double
- 7:49click on it then what should happen is
- 7:51Roblox studio is going to open up a new
- 7:54window that's going to be reserved
- 7:57exclusively uh or not exclusively but
- 7:59specifically for this game that we are
- 8:02creating so I'm just going to let Roblox
- 8:04Studio load this up really quick uh so
- 8:06that we can be connected into this new
- 8:09game and so now as you can see once we
- 8:12are loaded in we have a fresh base plate
- 8:15to work with and if we go to places we
- 8:18can still see that these places are
- 8:19connected with each other just ignore
- 8:21this one test place one for now just
- 8:22pretend that there's two places here so
- 8:24one for the main game and one for the
- 8:26place that we just created so this name
- 8:28for this place is kind of weird so so
- 8:29what I'm going to do is right click on
- 8:30it and hit rename so we're going to call
- 8:33this place two just to keep it simple uh
- 8:36so now we have place two and the the
- 8:39main game so we can actually just rename
- 8:41this to main game just to make it
- 8:43simpler so we have the main game and
- 8:45place two so that should be uh what we
- 8:48are working with as of right now okay
- 8:50and that's pretty much all it takes to
- 8:51create the second place uh within the
- 8:53same game so now what we're going to do
- 8:55is teleport the player to this place
- 8:58through script all right so I'm back
- 9:00into the main game and here's what we're
- 9:01going to do we're going to go on the
- 9:03right side of server script service
- 9:04we're going to hit the plus sign and
- 9:05we're going to insert a script so the
- 9:08first thing we're going to do is make
- 9:09reference to the service that we're
- 9:10going to be using which is of course
- 9:12teleport service so we're going to say
- 9:13local teleport service equals game colon
- 9:18get service open and close parentheses
- 9:21teleport service like this now there's
- 9:24two pieces of information that we need
- 9:26in order to teleport the player into um
- 9:29this this place so the first one is
- 9:31specifying exactly which place that we
- 9:34want to teleport the players to given
- 9:36their place ID so what we're going to do
- 9:38is go to our asset manager for place two
- 9:40we're going to right click on it and
- 9:42we're going to hit copy ID to clipboard
- 9:44so we're going to click that and then
- 9:45we're going to create a variable so that
- 9:47we know that this is the ID that we need
- 9:49so we're going to say local place ID
- 9:52equals and then we're just going to
- 9:54paste um the ID like this and so now
- 9:57that we have the place ID we need to
- 10:00specify the player that's going to be
- 10:02teleported or players in this case and
- 10:04an easy way we can do this is by making
- 10:07a player added event so that as soon as
- 10:09the player joins into the main game
- 10:11they're going to be teleported to the
- 10:12second place right away so what we're
- 10:15going to do is drop two lines and say
- 10:17game. players. player added colon
- 10:21connect function open close parentheses
- 10:23we're going to pass in the player
- 10:25argument and we're going to hit enter so
- 10:27what we're going to do is now say
- 10:29teleport service colon teleport async
- 10:34open and close parentheses and we're
- 10:36going to pass in the place ID and we're
- 10:38also going to pass in the players that
- 10:40are going to be teleported so in this
- 10:41case we're going to say player now there
- 10:44is something you have to be careful
- 10:45about this this is the first thing
- 10:47people get tripped up about and that is
- 10:50this takes in a table of players not
- 10:53just one player we're not just passing
- 10:55in one instance of the player to be
- 10:57teleported we need to pass in a table
- 10:59and so what we need to do is wrap this
- 11:02player in curly brackets to indicate
- 11:04that this is a table with one L that
- 11:07this is a table with one player inside
- 11:09of it and so this is a common thing
- 11:11people get tripped up about and you and
- 11:13you need to make sure that you have this
- 11:14taken care of okay great so this is
- 11:16basically our script right here but in
- 11:18order for us to test this script
- 11:19unfortunately we can't do this inside of
- 11:21Roblox Studio we're going to have to
- 11:23publish this game to Roblox so that we
- 11:26can play it in the game so that we can
- 11:28be teleported to this next place so what
- 11:30we're going to do is go on the top left
- 11:32hit file and we're going to hit publish
- 11:33to Roblox and if this is your first time
- 11:35publishing it just make sure that you
- 11:37create a new game um and have it be
- 11:41published to Roblox basically so another
- 11:44thing we need to make sure is to go to
- 11:46our second game like our second place
- 11:48and also publish that as well so we need
- 11:50to make sure that that is taken care of
- 11:51as well all right so we're in the second
- 11:53place hit file hit publish to Roblox and
- 11:56that is essentially taken care of now so
- 11:57what we can do now is go into the the
- 11:59actual game and test this for ourselves
- 12:01all right so this is what my published
- 12:03game looks like so I'm just going to hit
- 12:04play and then once we join into the
- 12:07place it's going to teleport us as soon
- 12:09as we join into the main game all right
- 12:11so I've now loaded into the main game
- 12:13after waiting for a bit as you can see
- 12:15the game has now teleported us to the
- 12:18second place that we specified um as
- 12:20soon as we joined into the main game
- 12:22we've now been teleported to the second
- 12:23place so it's basically working as
- 12:25expected this is the basics of using
- 12:27teleport service to teleport players
- 12:29from one place to the next so now that
- 12:32we know that teleporting Works another
- 12:34thing we can do is create our own
- 12:36loading screen or transition screen from
- 12:39one place to the next so uh we saw that
- 12:41when we teleported Roblox used their own
- 12:44default loading screen but we can
- 12:45replace that with our own loading screen
- 12:47if we wanted to and here's how it's
- 12:49going to work so we're first going to
- 12:51create it in starter GUI so we're just
- 12:52going to hit the plus sign and we're
- 12:53going to insert a screen GUI we're going
- 12:55to call this teleport GUI and and we're
- 13:00also going to check ignore GUI inset so
- 13:02we're going to check this off and what
- 13:04we're going to do is hit the plus sign
- 13:06create a frame we're going to surround
- 13:08the entire screen with this Frame so
- 13:10we're going to set the size of this to 1
- 13:13comma 0 comma 1 comma 0 like this and
- 13:15we're also going to change the
- 13:17background color to something dark
- 13:19probably like around here and we're also
- 13:22going to insert a text label inside of
- 13:23this Frame and we're going to move this
- 13:26text label uh down here and we're also
- 13:29Al going to drag this out just a little
- 13:31bit so that we can see it nice and big
- 13:33and we're also going to align this
- 13:35probably like somewhere down here so we
- 13:38need to make sure that the size is also
- 13:40using scale instead of offset so we're
- 13:42going to uh change these properties to
- 13:45zero and we're going to make the scales
- 13:48probably like let's say um
- 13:520.2 and we're going to make this one 0.4
- 13:55for the Y um or not we could just scale
- 13:58it like this now that we know that we're
- 14:00in the scale off that we're in the scale
- 14:02not the offset okay so now that we have
- 14:04that taken care of let's go down here
- 14:06let's uh scale the text like this let's
- 14:09change the text color to white and we're
- 14:12going to change the text to loading dot
- 14:15dot dot just like this and let's go back
- 14:18up and change the background color of
- 14:19this to something even darker than the
- 14:23the frames color so it's going to look
- 14:25like this and now we have a basic
- 14:27teleport um loading screen G thing not
- 14:30the best thing but it's something to
- 14:31work with so now that we have this we
- 14:34need a place to put this teleport GUI uh
- 14:36for for us to be able to access to be
- 14:39able to set this GUI so we're going to
- 14:41move teleport GUI into replicated
- 14:44storage now the thing about this is we
- 14:47have our teleport GUI but we need to be
- 14:49able to set our teleport GUI to this GUI
- 14:52in particular and the way we're going to
- 14:53do that is by creating a local script
- 14:56and having teleport servers set this GUI
- 14:58as the loading screen so this can only
- 15:01be done on the client as well so we need
- 15:04a place to put this local script so that
- 15:06we can access this teleport GUI so we're
- 15:08going to open up starter player and
- 15:10we're going to make a local script
- 15:12inside of starter player scripts so
- 15:14we're going to search up local script
- 15:15insert this and we're going to go back
- 15:18to our original script copy this
- 15:20reference to teleport service and we're
- 15:22going to insert it into here so now what
- 15:25we're going to do is also make reference
- 15:26to the teleport GUI so we're going to
- 15:28say local teleport guy equals game.
- 15:31replicated storage wait for Child open
- 15:34and close parenthesis teleport guy like
- 15:36this and so all it takes is just one
- 15:40simple method and it's simply just
- 15:43teleport service colon set teleport GUI
- 15:49open and close parenthesis and we're
- 15:50going to set it to the teleport GUI like
- 15:53this so that is essentially it so now
- 15:56we're going to hit save we're going to
- 15:58hit public and I'm going to demonstrate
- 16:00what this looks like once we join into
- 16:01the game all right so I've joined into
- 16:03the game and in a little bit we should
- 16:05see that our new loading screen has
- 16:07showed up rather than roblox's default
- 16:09loading screen if you want to have a
- 16:10side-by-side comparison we were able to
- 16:12see our loading screen versus roblox's
- 16:15default one so that's a simple way to
- 16:17add your own custom loading screen if
- 16:19you want to um make it look more nice
- 16:21for your game okay now there's something
- 16:23I want to add on to the guy that that
- 16:26you might think would be pretty helpful
- 16:28so what you saw with that transition it
- 16:30was only for like maybe uh a few seconds
- 16:33and then we were able to instantly be
- 16:34teleported into the game but what if we
- 16:36wanted to have a more smooth transition
- 16:38of like let's say uh a cut scene plays
- 16:41if um if the player teleports to this
- 16:43other game or if you want uh to add more
- 16:46to the teleport GUI after they load into
- 16:48the game like let's say there's a
- 16:50loading bar that shows up and then it's
- 16:51going to show that there's a completion
- 16:53that happens uh and then it transitions
- 16:55you over to whatever you want to do
- 16:56within the second game that's just an
- 16:58example I'm going to throw out there but
- 16:59essentially what we're doing is
- 17:01basically taking the GUI that's been
- 17:04sent over and use it uh to and use it
- 17:07however we want uh as soon as they load
- 17:09into the second game so what we're going
- 17:11to do is insert a local script inside of
- 17:14replicator first because this is the
- 17:15first thing we want to happen um once
- 17:18they teleport into the second game so
- 17:20we're going to hit the local script
- 17:23we're going to make reference to
- 17:24teleport service again so teleport
- 17:27service equals game col get service
- 17:30teleport service or teleport service
- 17:32like this and what we're going to do now
- 17:34is say teleport service colon get
- 17:40arriving teleport guy so this is what it
- 17:44looks like and we're actually going to
- 17:45make a variable um before it so we're
- 17:48going to say local teleport gy equals
- 17:51teleport service get arriving teleport
- 17:53GUI and there's also another thing we
- 17:55need to make reference to and that's
- 17:56going to be replicated first so we're
- 17:58going to say say local replicated first
- 18:01equals game get service replicated first
- 18:06and let's first check to see if this
- 18:08teleport guy is existent because
- 18:10sometimes it might not be so we're going
- 18:12to say if teleport GUI then we're going
- 18:16to hit enter like this and so what we're
- 18:17going to do now is essentially take the
- 18:20teleport GUI put it inside of uh the
- 18:23players's um player GUI and then for a
- 18:26specific amount of time we're just going
- 18:27to keep it there and then we're going to
- 18:28destroy so we're first going to make
- 18:30reference to the players's um player GUI
- 18:33and since this is local we can just say
- 18:35local player GUI equals game. players.
- 18:41local
- 18:43playerplayer guy like this and so
- 18:46another thing we need to do is remove
- 18:48the default loading screen as soon as we
- 18:50join into the game so we're going to say
- 18:52replicated first colon remove default
- 18:56loading screen like that and what we're
- 19:00now going to do is basically set the
- 19:03teleport GUI parent to the player gu so
- 19:05we're going to say uh teleport gy.
- 19:08parent equal to player gy like that and
- 19:14now what we're going to do is put a
- 19:16task. we for maybe about 5 seconds and
- 19:18then finally we're going to destroy the
- 19:21teleport GUI like this and so what
- 19:24should happen now is when we join into
- 19:25the second place it's going to take the
- 19:28teleport GUI that was um given to us and
- 19:31we're going to put it inside of the
- 19:33player GUI for five more seconds and and
- 19:35then we're going to destroy the teleport
- 19:37GUI after that so we're going to hit
- 19:39file publish to Roblox and now let's
- 19:42test the game all right so I'm loaded
- 19:43into the main game let's wait for the
- 19:44loading screen so the loading screen is
- 19:46here but it's waiting an additional 5
- 19:49seconds before it ends up destroying the
- 19:51loading screen so that we can see it
- 19:53better and have it do anything else that
- 19:55we wanted to I'm not going to show you
- 19:56complicated examples of this feature but
- 19:59it's important to know uh and be aware
- 20:01that this is something you can do with
- 20:04uh loading screen gys and all that sort
- 20:06of stuff so I hope this part has helped
- 20:07you all right the next thing I want to
- 20:09show you is teleport options now you
- 20:11might think what the heck is teleport
- 20:13options essentially what this is is that
- 20:15it gives us the ability to add more uh
- 20:19arguments to the teleport call that we
- 20:21have when we're sending players over
- 20:23from one place to the next and so this
- 20:25allows us to specify things like should
- 20:28the the player be sent to a reserved
- 20:30server or what kind of data do we want
- 20:33to send over to the server that we are
- 20:35teleporting the player to and just
- 20:37general things like that it's an
- 20:38important thing to know about and so
- 20:39that's what I'm going to be showing you
- 20:40how to do uh right now so let's go back
- 20:43to our script and what we need to do
- 20:46first we need to create a Teleport
- 20:48options instance uh so that we can pass
- 20:51that into this teleport async uh
- 20:53function call that uh is going to give
- 20:56more arguments to the teleport when we
- 20:59teleport the player to the next uh place
- 21:01so what we're going to do before the
- 21:03teleport ASN call we're going to drop
- 21:05two lines and at the top what we're
- 21:07going to do is say local teleport
- 21:10options equals instance. new open and
- 21:13close parentheses we're going to create
- 21:15teleport options like this and so now
- 21:18that we have teleport options we can add
- 21:20this as our third optional parameter
- 21:23here by putting in a comma and by
- 21:25specifying teleport options like this
- 21:29and so now uh what can we do with these
- 21:32teleport options one thing that we can
- 21:33do is specify if this should be a
- 21:35reserve server so we can do is drop a
- 21:37line down here and say teleport
- 21:40options. should Reserve server like this
- 21:45and we're going to set this equal to
- 21:46true so what will essentially happen
- 21:49here is as soon as the player joins into
- 21:51the game then they will be teleported to
- 21:53a reserved server where if a new player
- 21:56decided to join into the game they
- 21:57cannot join the same server as this
- 21:59player because the player that because
- 22:02the server that this player is in is in
- 22:04a reserved server so if I were to uh
- 22:07publish this game and test it then that
- 22:09is exactly what should happen so that is
- 22:12basically what goes on with Reserve
- 22:14servers and this is how you say to
- 22:16Roblox that we want you to create a
- 22:17reserve server for this player and
- 22:19things like that another thing we can do
- 22:21with teleport options is sending data
- 22:24between these different places so if you
- 22:26were to imagine that we're playing some
- 22:28sort of of matchmaking system uh inside
- 22:30of the main game that we want to send
- 22:32data over to the other place so that we
- 22:34know like the correct setup the
- 22:36configurations and things like that like
- 22:38let's say we were playing a tower
- 22:39defense game uh we would be specifying
- 22:41the difficulty that we'd be playing uh
- 22:43we would be specifying how many waves
- 22:44there would be we'd be specifying the
- 22:46map and how many players there are and
- 22:48just things like that simple data like
- 22:50that that we transfer between one place
- 22:52to the next for basic configurations and
- 22:55other and those sorts of things then we
- 22:57can do that by send in data through
- 22:59teleport options uh with the teleport
- 23:01async um method so here's what we're
- 23:04going to do we're going to create a
- 23:05table full of data that we're going to
- 23:07be sending over to the the other place
- 23:10so what we're going to do is say local
- 23:13teleport data equals open close hard
- 23:16brackets and we're going to hit enter
- 23:17like this so that we can specify for
- 23:19each entry there's going to be a
- 23:21specific data for each one so let's say
- 23:23we were playing a tower defense game
- 23:25then what we can do is say um I don't
- 23:27know we can specify
- 23:29difficulty set that equal to let's say
- 23:32hard and then we can say how many lives
- 23:34I don't know like three I don't really
- 23:35know how Tire defense games go so we can
- 23:37say lives uh we can say the number of
- 23:41players we can set this equal to let's
- 23:44say two and just things like that like
- 23:46data like this we can send over with
- 23:48teleport async and now that we have our
- 23:50teleport data we need to specify uh the
- 23:54teleport data with teleport options so
- 23:56we're going to drop two lines and we're
- 23:57going to say teleport options colon set
- 24:02teleport data open and close parenthesis
- 24:05and then we're going to pass in teleport
- 24:07data like this so now that we have this
- 24:10uh we're going to be sending over this
- 24:11data over to uh the other place but now
- 24:14we need to catch this data in our second
- 24:16place so that we can actually use it so
- 24:18I'm going to show you what that looks
- 24:19like in a so I'm going to show you what
- 24:20that looks like right now but what we
- 24:22need to do is go to our second place now
- 24:24so I'm going to see you over there okay
- 24:26so I'm now in the second place and in
- 24:27order to catch this data we're going to
- 24:30create a script inside of server script
- 24:31service here and what we're going to do
- 24:34is create a player added event so we're
- 24:36going to say game. players. player added
- 24:39connect function open and close
- 24:41parentheses player pass that in like
- 24:43that now here's how we access the data
- 24:46so we need to First access what's called
- 24:49join data when the player joins into the
- 24:51game and it has all sorts of information
- 24:53that we might find useful but
- 24:55specifically what we need is the
- 24:57teleport data so we're going to do is
- 24:58say local join data equals player colon
- 25:03get join data open close parentheses
- 25:06like this and now in order to specify
- 25:09the teleport data what we're going to do
- 25:10is drop a line and say local teleport
- 25:13data equals join data. teleport data
- 25:18like this so now from this we can
- 25:20basically access everything that we've
- 25:22created inside of teleport data so we
- 25:24can say uh local difficulty equals tele
- 25:28Port data. difficulty we can even say uh
- 25:32local num or no just lives equals
- 25:36teleport data. lives and you kind of get
- 25:38the idea at this point so we can
- 25:40basically just print these out by saying
- 25:42uh difficulty uh concatenate this with
- 25:46difficulty and then we can also print um
- 25:49lives which is set equal to lives like
- 25:53this and so that is basically what's
- 25:55going to be printed out in the output
- 25:56once we test this out inside of the
- 25:59actual game so what I'm going to do
- 26:00again is go to file hit publish I'm also
- 26:03going to go to the main game go to file
- 26:05and then hit publish and so now let's go
- 26:07into the actual game and test this for
- 26:08ourselves all right so I've joined into
- 26:10the game yet again so after we wait for
- 26:12some time then what's going to happen is
- 26:14it's going to teleport us to the next
- 26:16game and let's actually open up the
- 26:18developer console so that I can show you
- 26:20that it works in the output so I'm going
- 26:21to hit F9 go to server and as you can
- 26:25see in the output it printed out our
- 26:27difficulty being hard and Our Lives
- 26:28being three we were successfully able to
- 26:31send data from the main game into this
- 26:33game so that we can now use this for
- 26:35whatever we want to use um for this
- 26:38place that we're now playing in okay now
- 26:40you might ask what kind of data should I
- 26:43send between these places versus if I
- 26:45were to use things like data stores to
- 26:48save data and then fetch them in this
- 26:49next place to that I say if you were to
- 26:52send data between uh servers or places I
- 26:56would just send basic configuration
- 26:58ations or settings kind of data that
- 27:00you'd send over so let's say if we were
- 27:03you doing a matchmaking system in a
- 27:04horror game uh we'd specify the number
- 27:06of players that have joined into the
- 27:08game we'd specify uh the difficulty we'd
- 27:10specify the map and so we can basically
- 27:13configure this game to accommodate for
- 27:16uh what data we sent over and things
- 27:17like that because sending data over
- 27:20through teleport is more unsecure and
- 27:23it's easier to be exploited so for
- 27:25things that need more security and
- 27:28things that need persistence between or
- 27:30across all places within the game like
- 27:33things like leader stats things like
- 27:34progression I would recommend using data
- 27:37stores and so I hope this part has
- 27:39cleared any confusion to you uh in order
- 27:41to decide what kind of data you want to
- 27:43send over through teleport service and I
- 27:45hope this part has helped you okay so
- 27:47now I want to explain the concept of
- 27:50place ID and job ID so there's a
- 27:53difference between these two and it's
- 27:54important to understand what makes them
- 27:56different so going back to our diagram
- 27:58that we had over here with the game and
- 28:00the multiple places we know what place
- 28:02ID is because that's basically how we
- 28:04able to just go to one of these places
- 28:07and copy the ID to the clipboard so that
- 28:08we can specify which place we want to
- 28:11teleport the player to um and things
- 28:14like that job ID is a little different
- 28:16however if we were to let's say create a
- 28:18public server inside of one of these
- 28:20places Then This Server essentially has
- 28:23its own ID and this is what's called the
- 28:26job ID so the pl
- 28:28has a place ID but each individual
- 28:31server if I were to have multiple
- 28:32servers each individual server has its
- 28:35own job ID and the reason it's important
- 28:38to know U when to use job ID is so that
- 28:41you can specify like let's say if a
- 28:43player joins into the main game then we
- 28:45want to have them teleport to a very
- 28:47specific server um contained within uh
- 28:51one of these places that are currently
- 28:53active and so if you know how to use job
- 28:55ID then you know how to send players to
- 28:58a very specific server that's running
- 29:01and that's what I'm going to be showing
- 29:02you how to do right now in this uh
- 29:04section so going back to our script as a
- 29:06basic example what I'm going to do is
- 29:09add a a piece of information in the
- 29:11teleport data that's going to be this
- 29:13current games' uh job ID and so when we
- 29:16send that over to the second place we
- 29:18can see that there is a difference
- 29:20between job IDs so what we're going to
- 29:22do is drop a line down here in teleport
- 29:24data we're going to say job ID equals
- 29:27game . jobid and it's it's as simple as
- 29:31that and so once we have that taken care
- 29:33of what we're also going to do is print
- 29:35what this actual job ID is inside of the
- 29:37main game's output so that we know that
- 29:39there is a difference so we're going to
- 29:40say print open close parentheses game.
- 29:43jobid like this and so once we have that
- 29:45taken care of let's go into place two
- 29:48all right so we're in place two we're
- 29:49going to drop a line down here and we're
- 29:51going to make the same print statement
- 29:52by saying game. jobid like this and now
- 29:57what we're going to do is is specify uh
- 29:59the job ID property or the job ID data
- 30:03so we're going to say local job ID
- 30:06equals teleport data. jobid like that so
- 30:10now we're going to do is print um
- 30:13previous places job ID and then
- 30:18concatenate the job ID like this and so
- 30:21now essentially what's going to happen
- 30:23is we're going to start from the main
- 30:25game so the main game here is is going
- 30:28to specify its job ID of the main game
- 30:31and it's going to send that over to the
- 30:33second place the second place is going
- 30:35to print its own job ID and it's also
- 30:38going to print the job ID from the
- 30:41previous place which is the main game so
- 30:44now what we're going to do is hit
- 30:45publish on both of these
- 30:47games and let's go and try this out all
- 30:50right so I'm loading into the main game
- 30:51and very quickly when we go to the
- 30:53server we can see this long string of
- 30:55text that was the job I did of the main
- 30:59game's server so now if we hit on server
- 31:02in the second game we can see at the top
- 31:05that this is our Uh current games' job
- 31:09ID which is this ID here and as you can
- 31:11see uh it printed the exact same job ID
- 31:15from the previous game into this one so
- 31:17we can definitely see there's a
- 31:18difference between these two and if we
- 31:20can capture uh the job ID of a specific
- 31:23server that's how we know to send the
- 31:26player to a specific server and now I'm
- 31:28going to show you what this looks like
- 31:30through a practical example okay so
- 31:32here's what we're going to do I'm going
- 31:34to make it so that when uh let's say one
- 31:36of my friends join into the server and
- 31:39they are inside of a different place in
- 31:41the same game I wanted so that if I hit
- 31:43follow on their profile like if I go to
- 31:45their profile and follow them into the
- 31:47game I want to be spawned into the same
- 31:50place that they're in not the same game
- 31:52because by default if you were to follow
- 31:54uh one of your friends into a Roblox
- 31:55game then they would be sent to the main
- 31:58game rather than the actual place that
- 32:00they're in and so in order for us to be
- 32:01able to know which server and which
- 32:04place they're in specifically we're
- 32:06going to need to know their place ID and
- 32:08their job ID and so that's what I'm
- 32:10going to be showing you how to do inside
- 32:11of the script but it's mostly just going
- 32:14to be for um for testing and
- 32:17demonstration purposes so here's what
- 32:19we're going to do I'm going to go into
- 32:20the script and the first thing we're
- 32:22going to do is actually comment out the
- 32:24reserve server um check right here uh
- 32:27the
- 32:28Reserve server flag right here because
- 32:31this will not work if the if your friend
- 32:33is inside of a reserved server you
- 32:34cannot join a reserved server and here's
- 32:37what we're going to do at the very top
- 32:39I'm going to specify if the player if
- 32:43the player's name is equal to uh a very
- 32:45specific player like my ALT account so
- 32:47I'm going to say
- 32:49Blasberg then that's going to be the
- 32:51name of my ALT account and then I'm
- 32:52going to place all of this from here
- 32:54inside of here now again this is just
- 32:56for testing purposes because because
- 32:58what would normally happen is if I was
- 33:00inside of a game and I let's say was
- 33:02using a matchmaking system to have the
- 33:04player join a different game then we're
- 33:06going to specify through that rather
- 33:08than this check that's happening here
- 33:10but as of right now for this
- 33:12demonstration I'm going to do this uh
- 33:14alt account check and you can do this as
- 33:16well with your alt account if you want
- 33:17to try and uh play on multiple devices
- 33:19at the same time but this is essentially
- 33:21what I'm going to do so if let's say I'm
- 33:24playing on my alt account then it's
- 33:25going to teleport me to this new place
- 33:28and if I'm not my ALT account like let's
- 33:31say I'm on my main bra braw battle
- 33:33account then I want to try and follow um
- 33:37my ALT account to the place that he's in
- 33:39specifically and there's a property for
- 33:41this that we can uh check to see whether
- 33:43this is the case or not and that's
- 33:45called follow user ID so this is what
- 33:47it's going to look like we're going to
- 33:48say local follow user ID equals
- 33:54player. follow user ID like that and
- 33:58we're first going to make a check by
- 33:59saying if follow user ID and follow user
- 34:03ID does not equal to zero then because
- 34:06essentially follow user ID is the thing
- 34:08that's passed to us if we follow a
- 34:11player specifically through their
- 34:12profile and if it's not zero so it
- 34:15actually is legitimate then we're going
- 34:17to go down here and make that check for
- 34:19ourselves and continue with teleporting
- 34:22our player to the alt account so now
- 34:24what we need to do is fetch the
- 34:26information of the player that we're
- 34:29trying to follow with the place ID and
- 34:31also the job ID now we can do this using
- 34:34a PE call because uh this has the
- 34:36potential to fail so that's why we need
- 34:38to be able to do that so what we're
- 34:39going to do is say local success error
- 34:43message and then there's going to be
- 34:46three other variables here I'm going to
- 34:48explain what these are just a little bit
- 34:49but we're going to say current uh
- 34:52instance Place ID and job ID we're going
- 34:55to set this equal to P call
- 34:58function function open close parentheses
- 35:01enter and then what we're going to do is
- 35:03say return teleport service colon get
- 35:08player Place instance async open close
- 35:12parenthesis and then we're going to pass
- 35:14in the follow user ID so follow user ID
- 35:18now the reason it's structured like this
- 35:20is because get player Place instance
- 35:23async returns a tupal and if you
- 35:25remember what a tupal is it's not the
- 35:27same thing as a table it's basically
- 35:29multiple values paired together to have
- 35:32this be the return result uh as these
- 35:35three variables right here because as
- 35:36you know the first two variables success
- 35:39and error message that's going to be
- 35:40passed back with P call but get player
- 35:43instance async is going to pass back
- 35:44three values that we need uh in order to
- 35:48uh know what place and what server this
- 35:51fallo user ID uh person is in I hope
- 35:54this part is making sense so far um if
- 35:56you need to recap on PE call you can
- 35:58watch my data source videos on that but
- 35:59I hope that this part is making sense to
- 36:01you so far so once we have the
- 36:03information of the place ID and the job
- 36:04ID that's when we can teleport um the
- 36:07player to the follow user ID's uh place
- 36:12and um server so what we're going to do
- 36:14is say if success so if this was
- 36:16successful then we're going to say
- 36:18teleport service colon teleport to place
- 36:23instance so we're not using teleport
- 36:25async we're specifically using teleport
- 36:28two player instance we're going to put
- 36:30open close parentheses first thing we're
- 36:32going to do is specify the place ID
- 36:34second thing is specify the job ID and
- 36:37then finally we're going to specify the
- 36:39player we're teleporting now keep in
- 36:41mind for this instance we're just
- 36:43passing in one player and it's not a
- 36:46table of players so we can just simply
- 36:48say player like that and if this was not
- 36:52successful then we're going to put a
- 36:53warning message for the error message uh
- 36:57like this
- 36:58for the error message just like that and
- 37:01this is essentially the script that we
- 37:03we're going to be using uh to have our
- 37:05alt account join into the second place
- 37:07and then have brawl battle like our main
- 37:10account follow uh my my ALT account into
- 37:15that specific place and so now I'm going
- 37:17to show you what this looks like in game
- 37:18so I'm going to hit file hit uh publish
- 37:21to roblo make sure you always do that
- 37:23and now let me demonstrate this for you
- 37:24all right so here's what we have going
- 37:26on here so I'm on my ALT account right
- 37:28now Blasberg and I've currently been
- 37:30teleported to the second place in the
- 37:32game so now what I'm going to do
- 37:35is go into the Roblox homepage and go to
- 37:39my ALT account and I'm going to join his
- 37:41game directly so now what's going to
- 37:43happen is once I follow him into the
- 37:45game it's going to look for the follow
- 37:47ID and if it's valid then it's going to
- 37:49teleport me to the specific place and
- 37:51server that my ALT account is in rather
- 37:54than just the lobby or the default Place
- 37:56itself so we're going to wait for that
- 37:58to load okay and as you can see as soon
- 38:00as I joined into the game I
- 38:02automatically got teleported to um the
- 38:05server and or the place and the server
- 38:08that my ALT account was in and so this
- 38:10is how we can specify how we can
- 38:12teleport uh specific players to specific
- 38:14servers now of course there's other ways
- 38:16you can do it um but this is one way
- 38:18that I know is very practical to use
- 38:20inside of your Roblox game and so I
- 38:22wanted to demonstrate this example right
- 38:23here now again if things have confused
- 38:25you up until this point then I suggest
- 38:27you re-watching certain parts of the
- 38:28video that you think may have confuse
- 38:30you but this is a really good way to
- 38:32understand the difference between place
- 38:34and the place ID and job ID and how we
- 38:37can um bring and how we can bring
- 38:40players into specific servers because of
- 38:42that and I hope this part has made sense
- 38:43to you so far okay and the last thing I
- 38:46want to show in this video is being able
- 38:48to handle failed teleports because the
- 38:51network can be bad for a lot of people
- 38:53depending on what device they play on
- 38:54and things like that teleports can
- 38:56definitely fail a lot of the time and we
- 38:58need to be able to make sure that if it
- 39:01fails once then we need the server to
- 39:03keep trying to uh teleport the player
- 39:05until it is successful and if we just
- 39:08have one call with teleport async it's
- 39:10not exactly going to work so what we
- 39:12need to do is have a module that
- 39:14basically allows us to safely teleport
- 39:16the player and have it constantly retry
- 39:20uh to make sure that the players is
- 39:21being teleported uh safely and there is
- 39:24a really good module for this that's
- 39:25actually in the documentation I will
- 39:27have a link to this in the description
- 39:29of this video uh it's in the handling
- 39:31fail teleport section and basically what
- 39:34we're going to do is copy this script
- 39:36and have it in a module so that I can
- 39:37show you how this works and I'm going to
- 39:39step through um what the script does and
- 39:42things like that so with the handled
- 39:43fail uh teleport section I'm going to
- 39:45hit copy uh this entire code and we're
- 39:48going to go back to the main game so
- 39:50what I'm going to do is go to replicated
- 39:53storage and I'm going to hit the plus
- 39:54sign and I'm going to insert a module
- 39:57script
- 39:57because this is essentially a module
- 39:59script that has a function that allows
- 40:01us to safely teleport the player to a
- 40:04game with the specified ID and
- 40:06everything like that so I'm going to
- 40:08rename this to Safe teleport and then
- 40:12I'm going to select everything and I'm
- 40:14going to hit control B to paste uh the
- 40:16entire code like so and so now what
- 40:19we're going to do is go to our main
- 40:21script and what I'm going to do at the
- 40:23top here is require our module script so
- 40:26we're going to say local safe teleport
- 40:30equals game. replicated storage colon
- 40:33wait for Child open and close
- 40:36parentheses uh safe teleport and I'm
- 40:38also going to wrap this around in a
- 40:41requir call because we're trying to get
- 40:43a module script just like this and so
- 40:46now what we can do instead of teleport
- 40:48async is that we can actually replace
- 40:50this with safe teleport like this so we
- 40:54can specify the place ID we can specify
- 40:58the uh amount of players inside of a
- 41:00table so we can just say player like
- 41:02this and then we can have our options
- 41:04with our teleport options like this so
- 41:06it's basically the exact same thing as
- 41:08up here with teleport async except we're
- 41:10using the safe teleport module instead
- 41:13of just having one teleport async called
- 41:15because this will uh will serveice way
- 41:18better than if we were to just call
- 41:19teleport async once so now I want to go
- 41:22to the script and try and help you
- 41:24understand what is happening here with
- 41:25this entire script so if we at the very
- 41:27bottom obviously this is a module script
- 41:29and what this is returning is a function
- 41:33and what is this function this function
- 41:35is called safe teleport and basically
- 41:38What's Happening Here is that if we go
- 41:39down to the script we can see that uh we
- 41:41have an event called teleport and it
- 41:43failed so this is within the event of a
- 41:46failed teleportation and if this does
- 41:48happen then what we're going to do is go
- 41:51and use this function which is handle
- 41:53fail teleport so there can be multitudes
- 41:56of reasons why why a Teleport has failed
- 41:58has the server been flooded was it just
- 42:00a simple failure then what we're going
- 42:02to do is have a little delay before we
- 42:05try and see if we can fix this and once
- 42:07we do do this then we're going to call
- 42:10this safe teleport function with the
- 42:13parameters that we've specified here up
- 42:15to this main function right here with
- 42:16safe teleport and so basically What's
- 42:19Happening Here is we have an attempt
- 42:20index and then we have this Loop
- 42:23structure going on here so we have a PE
- 42:25call that's basically going to use the
- 42:28same function we were trying to use with
- 42:29teleport async but it's going to
- 42:31repeatedly do this over and over again
- 42:33so it's going to add the attempt index
- 42:35by one every single time it attempts to
- 42:37do this and if it was not successful
- 42:38then we're going to wait for a retry and
- 42:41then we're literally going to go back up
- 42:43here again and we're going to try
- 42:44teleport async again to then uh have the
- 42:47attempt go up again and then it's going
- 42:49to keep on doing this over and over
- 42:51again until either it has been
- 42:52successful or if the attempt index has
- 42:55reached its limit by five like if it
- 42:57tried it five different times and so
- 43:00it's basically going to return the
- 43:01success and results of whether this was
- 43:03the case or not or it's going to throw
- 43:05in an error of whether this uh did not
- 43:07work or not and so that is essentially
- 43:09the safe teleport module that we are
- 43:12going to be using instead of just simply
- 43:15using teleport async and I hope that
- 43:17this has made sense you up until this
- 43:19point conceptually like once again if
- 43:21there's something you didn't understand
- 43:22just rewatch this part and I hope that
- 43:25this will click to you one day and
- 43:26you'll realize that yeah like all these
- 43:28things do happen for a reason and so
- 43:31that is what I wanted to demonstrate to
- 43:32you as a final part to this episode now
- 43:36with everything that I've showed you up
- 43:37until this point I want you to see if
- 43:39you can make this matchmaking system of
- 43:41basically having players step onto this
- 43:44pad and uh whenever it reaches a certain
- 43:47um threshold like let's say two players
- 43:49I want you to teleport all of these
- 43:51players within the pad to a specific
- 43:54server uh within a different place uh in
- 43:57the game and I also want you to send
- 43:59data that you might find useful to use
- 44:02uh in this other game that you're going
- 44:03to be um playing or you can try and
- 44:05apply this inside of your own game that
- 44:07you're currently uh working on uh
- 44:09because this is a really good practice
- 44:11uh if you want to make a matchmaking
- 44:12system or just have different places
- 44:15within uh the same game so and if you
- 44:18need help with this you can join my
- 44:19Discord server you can ask uh anybody
- 44:21inside of the community to help you with
- 44:23this sort of thing uh because this
- 44:25entire uh learning process is a
- 44:27Community effort and also with the
- 44:28effort of what you put into to learn
- 44:30these things and I want to encourage
- 44:32more of that so that's basically going
- 44:34to be it for this episode um this has
- 44:36been one of my favorite episodes in this
- 44:38uh Series so far because of how long it
- 44:39is and also how much information has
- 44:41been put inside of this video so
- 44:43whatever you can do to help this series
- 44:45by either liking this video commenting
- 44:47or sharing it with anybody else you know
- 44:50um that would be very very appreciative
- 44:52of you and I think that's basically
- 44:54going to be it for this episode if
- 44:56you're still confused confused about
- 44:57some of the concepts that I talked about
- 44:59in this video um especially with things
- 45:01like replicated first with loading
- 45:02screens uh or things with um PE calls
- 45:05like the data stores video I'm actually
- 45:07going to send you a link to the data
- 45:08stores video which I'm going to have for
- 45:10you right here to watch so go ahead and
- 45:11watch that if you haven't already and I
- 45:13will see you in the next episode take
- 45:16care
About this transcript
This page contains the full transcript of Teleport Service (Teleporting, Servers, Send Data) - Roblox Advanced Scripting #26 by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 9,067 words across 1,194 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.