YouTube2Text

Cross server matchmaking in roblox studio. — Transcript

by TextChanged · 2,102 words · 319 segments · language en · Watch on YouTube

Full transcript

  1. 0:00hey there fellow developers today we
  2. 0:02will be diving into the cross server
  3. 0:04matchmaking system in Roblox
  4. 0:06specifically the one versus one
  5. 0:08matchmaking where two similar level
  6. 0:10players will be matched up and
  7. 0:12teleported to a reserved server I'll do
  8. 0:14my best to explain how the system works
  9. 0:17however having a basic understanding of
  10. 0:19Roblox scripting is necessary to grasp
  11. 0:21its functionality you need to understand
  12. 0:24how memory store service messaging
  13. 0:26service and teleport service work so
  14. 0:29let's see how this system will work
  15. 0:31think of the memory store as a folder
  16. 0:34this folder will contain all the cues
  17. 0:36the cues which is a table data or also
  18. 0:39works like folders and name of the
  19. 0:41folder is the key that will help us to
  20. 0:42find the queue in the memory
  21. 0:44service now in the queue we will save
  22. 0:47the data of players who are in the queue
  23. 0:49as a
  24. 0:51table that table will contain the
  25. 0:53player's user
  26. 0:57ID and their level which will will be
  27. 1:00used for player
  28. 1:02matching now when a player joins the
  29. 1:04queue there are three possible scenarios
  30. 1:07the first scenario is when the game
  31. 1:09fails to retrieve the queue from the
  32. 1:11memory store although the chances are
  33. 1:13low it's not zero in this case we will
  34. 1:16just tell the player to try again later
  35. 1:19the second scenario occurs when the game
  36. 1:21successfully retrieves data but there's
  37. 1:23no actual queue stored in memory this
  38. 1:26happens because the data stored in the
  39. 1:27memory store service isn't permanent in
  40. 1:29will vanish upon reaching the maximum
  41. 1:32lifetime however there's no need to
  42. 1:34worry as every time a player joins or
  43. 1:36leaves the queue it resets the data's
  44. 1:38maximum lifetime data stored in the
  45. 1:41memory service can last up to 45 days
  46. 1:44essentially if no player interacts with
  47. 1:46your game until the lifetime limit is
  48. 1:48reached the queue will be deleted due to
  49. 1:50lack of activity it's kind of sad
  50. 1:53because no one's playing your game in
  51. 1:55these cases we simply create the queue
  52. 1:57and insert the player's data into it
  53. 2:15the third scenario occurs when the game
  54. 2:17successfully retrieves data from the
  55. 2:19memory store and finds the queue then
  56. 2:22the game will iterate through the data
  57. 2:24of every player in the queue to find a
  58. 2:25player with a matching
  59. 2:28level
  60. 2:32if it doesn't find a match it simply
  61. 2:34inserts the new player data into the
  62. 2:38queue if it finds a player with a
  63. 2:41matching level it first removes the data
  64. 2:43of the matching
  65. 2:46player then using the teleport Services
  66. 2:49Reserve server function it generates a
  67. 2:51reserve server and returns a access code
  68. 2:54now we'll create a table of data using
  69. 2:57both players user IDs and access codes
  70. 3:14finally using the messaging service we
  71. 3:16instruct all servers in the game to
  72. 3:18check if either of those players are in
  73. 3:20them if found they are teleported to the
  74. 3:22reserve server using the access code
  75. 3:25however there's still a problem is the
  76. 3:27messaging service doesn't support
  77. 3:29sending table type data directly hence
  78. 3:32we need to use the HD deep Services Json
  79. 3:34encode function to encode the
  80. 3:37table now that we have a basic
  81. 3:40understanding of how it will work let's
  82. 3:42proceed to creating the system firstly
  83. 3:45we need to publish the
  84. 3:58game
  85. 4:06after that we need to add another place
  86. 4:07where players will be teleported to do
  87. 4:10this go to the asset
  88. 4:13tab select
  89. 4:17places then right click and add a new
  90. 4:28place now add a script to the server
  91. 4:31script
  92. 4:36service firstly let's retrieve all the
  93. 4:38services and store them in a local
  94. 4:58variable
  95. 5:01now let's create a sorted map in the
  96. 5:03memory service and name it Q
  97. 5:09store this sorted map will work like the
  98. 5:11folder that holds all the other Q
  99. 5:13folders such as one versus one 2 versus
  100. 5:162 4 versus 4 Etc now let's add three
  101. 5:20remote events in the replicated storage
  102. 5:22and name them join leave and
  103. 5:25teleport also create three variables for
  104. 5:28each of them
  105. 5:36now let's create a function that detects
  106. 5:38when a player joins the game it will
  107. 5:41create a folder called leader stats and
  108. 5:43insert a number value called
  109. 5:46level while naming the folder leader
  110. 5:48stats isn't necessary for the
  111. 5:50matchmaking to work it allows us to see
  112. 5:52the level in
  113. 5:56game let's give it a go
  114. 6:02and now we can see the level on the
  115. 6:03right top
  116. 6:06Corner let's create the buttons to join
  117. 6:08and lead the
  118. 6:24queue next we'll insert a local script
  119. 6:27and create variables for the events
  120. 6:46we'll then detect when the player
  121. 6:47presses the join button and fire the
  122. 6:49join remote event additionally we'll
  123. 6:52make the join button invisible and the
  124. 6:54leave button visible now let's go back
  125. 6:56to the server script and detect when the
  126. 6:58join remote event fires connecting it to
  127. 7:01a function firstly we'll obtain the
  128. 7:03player's user ID and player
  129. 7:08level next we retrieve the queue from
  130. 7:10the memory store we'll enclose it in a
  131. 7:12PE call just in case something goes
  132. 7:15wrong and we don't want the whole script
  133. 7:16to break the P call function returns two
  134. 7:19values success indicating if it worked
  135. 7:22fine and result which Returns the Quee
  136. 7:25when success is true if success is false
  137. 7:28it Returns the errors that caused the
  138. 7:30failure Now using the get async function
  139. 7:33we will obtain the Q which takes the key
  140. 7:35as its parameter in my case the key is 1
  141. 7:38V1 as I mentioned earlier regarding the
  142. 7:41possible scenarios of retrieving the que
  143. 7:43from the memory store let's first handle
  144. 7:46the situation where we successfully
  145. 7:47retrieved the queue but there isn't any
  146. 7:49actual data this means the success value
  147. 7:52is true but result is nil in this case
  148. 7:55we will create a queue and upload it to
  149. 7:57the memory store let's create a
  150. 8:01table and inside that table we will
  151. 8:03create another table with the player's
  152. 8:05user ID as its Index this will help us
  153. 8:08find the players data easily later on
  154. 8:10when the players leave the queue now
  155. 8:13inside that table we will add the user
  156. 8:15ID in the level however there is another
  157. 8:18problem since we use the player's user
  158. 8:20ID as an index which is a number some
  159. 8:22players might get prioritized over
  160. 8:24others for example if a player with user
  161. 8:27ID 1 mil10 is in the queue and a new
  162. 8:30player joins with user ID 1,9 keeping
  163. 8:33the index as a number would put the new
  164. 8:35player in front of the previous player
  165. 8:37this is unfair and might cause longer
  166. 8:39wait times for some people to avoid this
  167. 8:42we will make the index a strain now
  168. 8:45let's upload the new queue to the memory
  169. 8:47store make sure to enclose this function
  170. 8:49in a p call the set a sync function
  171. 8:52takes three parameters the key the value
  172. 8:55and the duration I will create a local
  173. 8:57variable for the duration since we need
  174. 8:59to use it more than once I'll set the
  175. 9:02duration to 24 hours or
  176. 9:0486,400
  177. 9:05seconds now let's print out the results
  178. 9:08to make it easier to debug in the
  179. 9:21future now let's handle the second
  180. 9:24scenario where we successfully retrieved
  181. 9:26the queue and there is data meaning
  182. 9:28success is true true and result isn't n
  183. 9:31in this case we will iterate through the
  184. 9:33queue to find a player with a similar
  185. 9:40level when we find a matched player we
  186. 9:43will remove that player's data from the
  187. 9:45queue and upload it back to the memory
  188. 9:53store we'll save the player's data table
  189. 9:56in a local variable and break through
  190. 9:58the loop
  191. 10:02after the loop we will check if the
  192. 10:03match player variable is nil or not if
  193. 10:06not nil that means a match was found and
  194. 10:09we will create a table data with the
  195. 10:11user IDs of the two players and the
  196. 10:12reserve server code using the teleport
  197. 10:15Services Reserve server function this
  198. 10:17function takes the place's ID as its
  199. 10:19parameter to get the place ID go to the
  200. 10:22assets tab select places right click on
  201. 10:25the place and then copy the ID to the
  202. 10:28clipboard
  203. 10:36next we need to encode this data table
  204. 10:38using the HTT Services Json encode
  205. 10:41function after that we are ready to
  206. 10:43publish this message using the messaging
  207. 10:46service we will also enclose this in a p
  208. 10:49call the messaging services publish
  209. 10:51async function takes two parameters the
  210. 10:54topic which works like a key in the
  211. 10:58message
  212. 11:02following that we will print out the
  213. 11:15results now let's handle the scenario
  214. 11:18where we failed to retrieve the
  215. 11:22queue let's first create a text label
  216. 11:25that will inform the player that
  217. 11:26something went wrong and to try again
  218. 11:30we will make it invisible after that go
  219. 11:33back to the local script instead of
  220. 11:35directly making the leave button visible
  221. 11:37we will wait for the server's response
  222. 11:40let's create a local variable that will
  223. 11:42hold the response event and assign it to
  224. 11:44the join remote event function we will
  225. 11:46receive a message from the server after
  226. 11:49receiving the response we need to
  227. 11:50disconnect the function because it is
  228. 11:52not needed anymore I forgot to show it
  229. 11:54in the video but this is how it is
  230. 11:57done following that we will check what
  231. 12:01the message is if it is an error we will
  232. 12:03make the error text label visible wait
  233. 12:05for one second then make the text label
  234. 12:08invisible again and make the join button
  235. 12:15visible If the message is a success we
  236. 12:18will wait for a bit and then make the
  237. 12:20leave button visible now go back to the
  238. 12:23server script in the if statements where
  239. 12:25success is true we will respond with a
  240. 12:27success message and error message where
  241. 12:29success is
  242. 12:36false I forgot to mention the part where
  243. 12:39the match player isn't found in this
  244. 12:41case we can simply insert the player
  245. 12:43into the queue and upload it back to the
  246. 12:45memory
  247. 12:57store
  248. 13:21now we will teleport the players first
  249. 13:24we will get the message from the
  250. 13:25messaging service and decode it
  251. 13:31after that we will create a Teleport
  252. 13:33option and set its Reserve server access
  253. 13:36code property to the reserve
  254. 13:40code following this we will Loop through
  255. 13:43every player in this server and check if
  256. 13:45their user ID is the same as either of
  257. 13:47the two players in the message if it is
  258. 13:49the same then using the teleport
  259. 13:51Services teleport async function we will
  260. 13:54teleport them to the reserve
  261. 13:57server
  262. 14:09if the teleport was successful we tell
  263. 14:12the client that it is being teleported
  264. 14:13by using the teleport remote event let's
  265. 14:16create a blur effect and turn it
  266. 14:23off after that the client will listen to
  267. 14:26the event and enable the blur effect
  268. 14:28let's also create a text
  269. 14:44label now for the leave button the
  270. 14:47client side code is exactly the same as
  271. 14:49the join button I'll just copy paste the
  272. 14:52code and change the
  273. 14:57variables
  274. 15:01now for the server script we will first
  275. 15:03retrieve the
  276. 15:13queue then using the player's ID as an
  277. 15:16index we will check if the player's data
  278. 15:18is in the queue if it is we will remove
  279. 15:21that data from the queue upload it back
  280. 15:23to the memory store and send a
  281. 15:27response
  282. 15:59now we will fire the leave event when a
  283. 16:01player leaves the game just in case a
  284. 16:03player joins the queue and leaves the
  285. 16:05game pathetically we will also remove
  286. 16:08players from the queue when the server
  287. 16:10is about to shut
  288. 16:14down finally our system is complete but
  289. 16:18before testing we need to do a few
  290. 16:19things first make the game
  291. 16:23public turn on HTTP requests and third
  292. 16:27party teleport now publish the game also
  293. 16:31let's go to world one and change the
  294. 16:32color of the base
  295. 16:54plate at last we can test our game
  296. 16:57however there is a problem problem
  297. 16:58because we can't use Roblox multi-
  298. 17:00instance to run multiple accounts on the
  299. 17:02same device and run this system for some
  300. 17:04reason if we try to do so only one
  301. 17:07account will get teleported but the
  302. 17:09other account will encounter error
  303. 17:11773 attempted to teleport to a place
  304. 17:14that is restricted so we need to use
  305. 17:17different devices for each account I
  306. 17:19will use my phone for the other account
  307. 17:20and give it a
  308. 17:27try
  309. 17:48as we can see it works if you are still
  310. 17:50concerned you can always test it
  311. 17:52yourself link is in the description we
  312. 17:55have finished our journey here today
  313. 17:57hopefully you have learn learned
  314. 17:58something from this video liking and
  315. 18:00subscribing are highly appreciated if
  316. 18:03you still have lingering questions about
  317. 18:05anything leave them in the comment
  318. 18:06section and I will try my best to answer
  319. 18:09peace out

About this transcript

This page contains the full transcript of Cross server matchmaking in roblox studio. by TextChanged , generated from the public captions YouTube serves with the video. The transcript has 2,102 words across 319 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 translate the transcript into 100+ languages.

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, translation to 100+ languages, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.