YouTube2Text

Remote Events (One-Way Communication) - Roblox Advanced Scripting #5 — Transcript

by BrawlDev · 5,703 words · 770 segments · language en · Watch on YouTube

Full transcript

  1. 0:00hey thanks for stopping by we're going
  2. 0:02to be creating a bunch of stuff that
  3. 0:04correlates to server and client
  4. 0:06communication so that we can create
  5. 0:08systems that allows us to have more
  6. 0:10security with our Roblox games and also
  7. 0:12more robust systems with the things that
  8. 0:15we decide to create inside of our Roblox
  9. 0:17games and in this episode I'm going to
  10. 0:19be introducing two of them which are
  11. 0:22called remote events and remote
  12. 0:24functions and with them we're able to
  13. 0:26create things like this so I made a text
  14. 0:28label that says would you like to buy
  15. 0:30this button and I have a button down
  16. 0:32here that we can press called buy button
  17. 0:35and this costs 50 coins and up here you
  18. 0:38can see in my leader stats we have 50
  19. 0:40coins to be able to buy this so let's
  20. 0:41see what happens when I actually press
  21. 0:43it so essentially when I press this
  22. 0:47button it communicated to the server to
  23. 0:49check whether I had 50 coins or not and
  24. 0:51if it did then it will then it would
  25. 0:53subtract 50 coins from my leader stats
  26. 0:56and it would tell us the message that
  27. 0:59the purchase has been been successful by
  28. 1:01updating this text label if we press it
  29. 1:03again now that we can't afford it uh it
  30. 1:06will check again but this time we can't
  31. 1:09afford it so the server will tell the
  32. 1:11client that the purchase has failed I
  33. 1:14want you to understand what goes on
  34. 1:17behind the scenes when we're
  35. 1:19communicating with the server and client
  36. 1:21and why this matters a lot when we're
  37. 1:23dealing with security and exploitation
  38. 1:26and all those other sorts of things but
  39. 1:28before we start implementing let me show
  40. 1:30you something else all right let's think
  41. 1:32about this for a minute so if you saw
  42. 1:34one of my previous episodes you might
  43. 1:35find this diagram to be familiar and yes
  44. 1:38this is the server and client model uh
  45. 1:40found on the Roblox developer Hub that's
  46. 1:43because in this episode I feel like this
  47. 1:46really ties back into what we're going
  48. 1:48to be doing inside of this episode so if
  49. 1:50you remember the game consists of two
  50. 1:53sides you have the server and the client
  51. 1:55the server up here is basically the
  52. 1:58perspective of the game
  53. 2:00that has access to everything inside of
  54. 2:03the server and also in the client but if
  55. 2:06you're a but if you're one of these
  56. 2:08clients attached to the server also
  57. 2:10known as The Players so we have player
  58. 2:13one down here and then we have player
  59. 2:14two and then player three all within
  60. 2:17their own perspectives of the game do
  61. 2:19not have access to whatever information
  62. 2:22is in the server the server is the
  63. 2:24PowerHouse of all its valuable
  64. 2:27information that the client cannot not
  65. 2:30simply access just freely that's why
  66. 2:32there has to be communication between
  67. 2:35the server and the client whether that
  68. 2:37would be from whether that would be from
  69. 2:39this player so let's call this player
  70. 2:40one if it wanted to send information to
  71. 2:43the server then we will use a remote
  72. 2:46event to be able to tell the server we
  73. 2:48wanted to do something and it'll do it
  74. 2:51for us or if we have information to a
  75. 2:54specific player from the server we will
  76. 2:56go from the server and we will send
  77. 2:58information to a specific player play
  78. 3:00like let's say player 2 to tell them
  79. 3:02that they to tell them that they got a
  80. 3:04notification or something or if we're
  81. 3:06playing a round based game then we will
  82. 3:08have the server replicate to all the
  83. 3:11players inside of the game that if this
  84. 3:14is a round based game that the game is
  85. 3:15over and it's going to reset everything
  86. 3:19to wait for the next game to happen so
  87. 3:22there's so many use cases where we would
  88. 3:24have to communicate with the client and
  89. 3:27the server to get stuff done to make
  90. 3:29systems robust to make it very secure
  91. 3:32from hackers because that's one of the
  92. 3:34main important things we need to know
  93. 3:36about here is that even if it's not for
  94. 3:38security there's a lot of things you
  95. 3:40can't do unless you know how to
  96. 3:42communicate with the server and client
  97. 3:43so that's why it's very important to
  98. 3:46understand how this stuff works when to
  99. 3:47use it and why you should use them and I
  100. 3:51hope this gave you a little more insight
  101. 3:52as to what we're going to be doing in
  102. 3:54this episode now that we understand it
  103. 3:56let's make some stuff that effectively
  104. 3:58communicates between the the server and
  105. 4:00client so first thing we will do is
  106. 4:03create a leader stats script to give
  107. 4:05ourselves some coins so we're going to
  108. 4:08go to the server script service and
  109. 4:10we're going to make a script and we're
  110. 4:13going to rename the script to leader
  111. 4:16stats I'm not going to write all this
  112. 4:17out uh I'll just like quickly copy and
  113. 4:19paste a code that I've already had from
  114. 4:21a previous episode yeah so just to save
  115. 4:23us a bit of time I created I quickly
  116. 4:26created a player added event where we
  117. 4:28created a leader stats fold and we
  118. 4:30created a coins uh int value with a
  119. 4:34default value of 50 so that we have some
  120. 4:36coins to work with um but we're going to
  121. 4:39basically but basically what we're going
  122. 4:41to do first is create a remote event and
  123. 4:44how we can communicate from the client
  124. 4:47to the server we're basically going to
  125. 4:48create a button here that says give
  126. 4:50currency and when the player presses
  127. 4:52that button it's going to send a message
  128. 4:54to the server to give our player
  129. 4:58currency and I me mentioned that this is
  130. 5:00going to be a remote event so you might
  131. 5:03ask where do we create this remote event
  132. 5:05for the most part I would say create it
  133. 5:07inside of replicated storage I'd say
  134. 5:09this is the best place to access
  135. 5:11information that we want to know about
  136. 5:13from the server and also the client
  137. 5:16because as you know there are specific
  138. 5:18folders inside of the game that can only
  139. 5:20be accessed by either the server or the
  140. 5:22client for instance server script
  141. 5:25service and server storage these can
  142. 5:26only be accessed on the server but
  143. 5:28things like
  144. 5:30starter GUI starter pack starter player
  145. 5:33these things can can be accessed on the
  146. 5:35client but we want a folder that can be
  147. 5:38accessed from both the server and the
  148. 5:40client which is usually replicated
  149. 5:42storage and replicated first but we're
  150. 5:44going to put it inside of replicated
  151. 5:46storage so we're going to hit the plus
  152. 5:47sign and let's insert a remote event
  153. 5:51this is what it should look like and
  154. 5:53let's rename this remote event to give
  155. 5:57currency so this is what we're going to
  156. 5:59use to tell the server that we want to
  157. 6:02give the player currency whenever we uh
  158. 6:04press a button now let's actually create
  159. 6:06the button so let's go to starter GUI
  160. 6:09hit the plus sign we're going to create
  161. 6:10a screen GUI we're going to then hit the
  162. 6:13plus sign here and create a text button
  163. 6:16so here's our text button let's just
  164. 6:18drag this alongside here so let's change
  165. 6:22text scale to true and we'll name this
  166. 6:24text give currency and now let's create
  167. 6:28a local script inside of the screen GUI
  168. 6:31so we'll make a local script let's first
  169. 6:33make reference to the screen GUI which
  170. 6:36is going to be local GUI equals script.
  171. 6:41parent and then we'll first make
  172. 6:42reference to the text button but let's
  173. 6:44actually rename this text button to give
  174. 6:48currency so local give button equals GUI
  175. 6:53dog currency and finally we'll make
  176. 6:56reference to our give currency remote
  177. 6:59event which is located inside of
  178. 7:01replicated storage so down here we're
  179. 7:04going to say local give currency equals
  180. 7:08game. replicated storage it's inside of
  181. 7:12our replicated storage folder. give
  182. 7:15currency so now that we have our
  183. 7:16references let's create the mouse button
  184. 7:19one click event when we press the button
  185. 7:20so we'll say give button. Mouse button
  186. 7:24one click colon connect function and
  187. 7:29then then drop a line down here we want
  188. 7:31to fire the event so that when we go
  189. 7:34back to the server we can catch that
  190. 7:36event when it's being activated and the
  191. 7:38way we activate this event is by saying
  192. 7:41give currency which is our remote event
  193. 7:44colon fire server so when we press the
  194. 7:48button we're going to fire this remote
  195. 7:51event to the server and we're going to
  196. 7:53have the server take this function call
  197. 7:56which I will show you in a little bit
  198. 7:57there are multiple arguments we can put
  199. 7:59in in here but just for right now we're
  200. 8:01going to leave this empty so now let's
  201. 8:03catch this inside of the server uh we're
  202. 8:05going to copy this reference right here
  203. 8:07so we're going to highlight this and
  204. 8:08copy and we're going to go to our leader
  205. 8:10stat script so down here let's drop two
  206. 8:13lines and let's just control V to paste
  207. 8:16our copy code and now what we'll do is
  208. 8:20we will catch this fired event we'll say
  209. 8:23give currency and it's going to be dot
  210. 8:27on server event colon connect function
  211. 8:34and here's what's really important about
  212. 8:35this so whenever we call fire server we
  213. 8:39don't pass anything here but indirectly
  214. 8:42it's automatically going to pass in the
  215. 8:45player object that called this event so
  216. 8:49it's going to be our player in the game
  217. 8:51that called this event when we pressed
  218. 8:53the button so we're going to pass in the
  219. 8:55player argument and this is required you
  220. 8:58have to have the first argument be the
  221. 9:00player and anything after that is
  222. 9:03basically just going to be uh whatever
  223. 9:06arguments we put inside of our function
  224. 9:09call but for right now it's just going
  225. 9:11to be player so now that we understand
  226. 9:12that let's locate our coins in value
  227. 9:15inside of our leader stats so we're
  228. 9:17going to say local leader stats equals
  229. 9:21player do leader stats and then we will
  230. 9:25make reference to the coins we will say
  231. 9:27local coins equals leader stats. coins
  232. 9:31now let's add coins to the int value so
  233. 9:34we'll say coins. Val plus equals let's
  234. 9:38just say 50 all right so essentially
  235. 9:39what we've done is that we created a
  236. 9:41text button that says give currency when
  237. 9:44we press it it's going to send a message
  238. 9:47to the server and it's going to catch it
  239. 9:50onto the server that we want to give the
  240. 9:53player that called this remote event to
  241. 9:56give them 50 coins and I will explain to
  242. 9:58you why this is important but let's test
  243. 10:00this out first so we going to go to the
  244. 10:02game hit test and hit play and see the
  245. 10:05new button that we just created all
  246. 10:07right so I've spawned into the game our
  247. 10:08coins by default is 50 but if I press
  248. 10:11give currency then it should effectively
  249. 10:14give 100 coins to the to the player so
  250. 10:19if we keep pressing it then we should
  251. 10:21constantly be getting 50 coins every
  252. 10:23time we press the button so that should
  253. 10:25be working as expected but now you might
  254. 10:27ask why do we need need this server and
  255. 10:29client communication when we're let's
  256. 10:32say giving currency to a player so in
  257. 10:34order for me to explain that let me go
  258. 10:36back into the game and like I mentioned
  259. 10:38with the server and client model there's
  260. 10:39you can go between the server and client
  261. 10:42window by going to test and then hitting
  262. 10:44this button here uh by telling you
  263. 10:46whether you're on the server side or if
  264. 10:47you're on the client side right now I'm
  265. 10:49on the server side but if I press it
  266. 10:51again I'm going back to I'm back to the
  267. 10:53client side so let's see what our coins
  268. 10:57value actually looks like when we're on
  269. 11:00both sides of the game so we're going to
  270. 11:02go to players brawl battle leader stats
  271. 11:04coins so as you can see my coins int
  272. 11:07value is 50 like expected let's see what
  273. 11:10happens if I change the value in the
  274. 11:13client so if I just change this value to
  275. 11:17200 then it'll show that my coins have
  276. 11:20been updated to 200 and my coins in
  277. 11:23value has also been updated to 200 but
  278. 11:26what's the problem here it looks like
  279. 11:27it's working as expected if we go into
  280. 11:29the server side so if I click our server
  281. 11:32window and we do the same thing where we
  282. 11:35and we do the same thing where we go to
  283. 11:37players we go to brawl battle the leader
  284. 11:39stats and coins we can see that our
  285. 11:42value is still 50 despite US changing
  286. 11:45the value inside of our local client
  287. 11:48this is why I must reiterate that the
  288. 11:50communication between the server and
  289. 11:52client is very important because what
  290. 11:54you see inside of the client is not
  291. 11:57going to be replicated to the server for
  292. 12:00all the other players it's not going to
  293. 12:02be the same thing so if I had a shop
  294. 12:04system this actually is not 200 coins
  295. 12:08but in reality the game says that my
  296. 12:10player has 50 coins instead of 200
  297. 12:14that's why when we're updating or in
  298. 12:16this case giving currency we need to
  299. 12:18tell the server to give us 50 coins not
  300. 12:21the client that's why we have to do this
  301. 12:23whole server and client model with tell
  302. 12:26with creating a remote event firing the
  303. 12:28server and then making the server catch
  304. 12:31this event to then update our coins
  305. 12:34value because we could have just simply
  306. 12:36done this inside of our local script but
  307. 12:38this wouldn't have actually given the
  308. 12:41player the coins that we want to give
  309. 12:43the player this would have made us think
  310. 12:46in the client that we would have that we
  311. 12:48gave ourselves coins but in reality the
  312. 12:50game says we did not do anything because
  313. 12:53this is very easily exploitable for any
  314. 12:56hacker or exploiter inside of a Roblox
  315. 12:58game to give themselves a a huge
  316. 13:01ridiculous amount of coins inside of the
  317. 13:03game so that they can buy everything
  318. 13:05inside of the game that's why we rely on
  319. 13:08the server to do all this for us not the
  320. 13:11client so I hope this give you a better
  321. 13:12explanation and a better understanding
  322. 13:15of why we do these things all right so I
  323. 13:17mentioned extra parameters being extra
  324. 13:20arguments or parameters being a thing
  325. 13:22for remote events and that's what I'm
  326. 13:24going to show you really quickly here so
  327. 13:27when we have a remote event it doesn't
  328. 13:30matter how many arguments we throw into
  329. 13:31here because we can have as many as we
  330. 13:33want um this is usually to pass in
  331. 13:36information to the server um using this
  332. 13:39remote event if we want it to do
  333. 13:41anything specific uh it gives us more
  334. 13:44power to be able to say exactly what we
  335. 13:46want to do with uh arguments that we
  336. 13:49pass into to this event call so in this
  337. 13:53case we have give currency which gives
  338. 13:55us 50 which gives us a fixed amount of
  339. 13:59coins every single time we press the
  340. 14:00button but what if we wanted to specify
  341. 14:02it on the client um we would do that by
  342. 14:04creating parameters and passing in
  343. 14:06arguments to our function calls so we're
  344. 14:09going to create another parameter here
  345. 14:11after player by putting in a comma and
  346. 14:13this is going to be the coins amount uh
  347. 14:18and we're going to take this coins
  348. 14:19amount and we're going to replace it
  349. 14:21with our fixed 50 currency that's over
  350. 14:24here so now what we're going to do is
  351. 14:28we're going to go to to our uh fire
  352. 14:30we're going to go to our local script
  353. 14:32and inside of this fire server remember
  354. 14:34that player is implicitly passed into
  355. 14:38our function call so we actually don't
  356. 14:40need to pass in player but rather we're
  357. 14:43going to pass in our coins amount so in
  358. 14:45this case it's going to be 50 so what's
  359. 14:48going to happen here is that when we
  360. 14:49call fire server we're going to pass in
  361. 14:52our our coins amount and over here it's
  362. 14:56going to implicitly pass in the play
  363. 14:58player argument and then our uh coins
  364. 15:02amount so it's very important to
  365. 15:04understand that we're not passing in
  366. 15:05player first this is actually our second
  367. 15:08argument which is our coins amount but
  368. 15:10over here we're going to pass in player
  369. 15:12first thing and then all the arguments
  370. 15:15afterwards that we uh provided inside of
  371. 15:18these parameters so if we go back and
  372. 15:20test it it should essentially do the
  373. 15:23exact same thing so if you press it then
  374. 15:25it should do what we needed to do so
  375. 15:27that works out wonders
  376. 15:29and like I mentioned uh you can have as
  377. 15:32many arguments as you want uh as long as
  378. 15:35you have this player parameter you can
  379. 15:37have as many arguments as you want here
  380. 15:39you can pass in as much information and
  381. 15:41the script will not complain about it so
  382. 15:43what we just did was we communicated
  383. 15:46from the from the client to the server
  384. 15:49but now what if we wanted to do it the
  385. 15:51other way around what if we wanted to
  386. 15:53communicate from the server to the
  387. 15:55client like for instance if if the
  388. 15:58player has joined the game then we will
  389. 16:00tell the server to send a message to the
  390. 16:02client to give them like a special
  391. 16:05greeting uh through text or something so
  392. 16:08that's what we're going to do with this
  393. 16:09example this can also be done by using a
  394. 16:12remote event so for this example we're
  395. 16:13going to create another remote event so
  396. 16:16like I said it's going to be inside of
  397. 16:17replicated storage cuz that's the folder
  398. 16:19I recommend putting all your remote
  399. 16:21events in uh so we'll hit the plus sign
  400. 16:23and we're going to create another remote
  401. 16:25event and we're going to rename this
  402. 16:27greet
  403. 16:29player and let's go back to our leader
  404. 16:32stat script so in our leader stat script
  405. 16:34let's make room for our reference to the
  406. 16:39Greet player uh remote event so we'll
  407. 16:41say local greet player equals game.
  408. 16:46replicated
  409. 16:47storage. greet player and so and now
  410. 16:51what we'll do is we'll drop two lines
  411. 16:53after we create the coins leader stat by
  412. 16:56saying greet player
  413. 16:59and you remember how we communicated
  414. 17:01from the client to the server so we took
  415. 17:04the remote event and we called fire
  416. 17:07server but this time what we're going to
  417. 17:09do is we're going to do the opposite
  418. 17:11we're going to say colon fire
  419. 17:15client so it basically does the opposite
  420. 17:18of fire server it just says fire client
  421. 17:20instead but here but here's the very
  422. 17:22important thing we we are required much
  423. 17:25like our on server event we're required
  424. 17:28to pass in the specific player we want
  425. 17:31to send this message to so in this case
  426. 17:35it's going to be our player which we
  427. 17:37labeled right here in our player uh
  428. 17:40variable so we're just going to Simply
  429. 17:42pass in player so this is the basic
  430. 17:45Syntax for our fire client event like
  431. 17:48like I mentioned before you can pass in
  432. 17:50other parameters if you really want to
  433. 17:52um but that is totally optional what is
  434. 17:54required is specifying which player
  435. 17:57we're trying to send this message to and
  436. 18:00like with our on server event we need to
  437. 18:04catch this call onto the client instead
  438. 18:06so in our local script uh we're actually
  439. 18:08going to copy our greed player reference
  440. 18:11and then we're going to paste it down
  441. 18:13here and then what we'll do is instead
  442. 18:18of on server event we're going to say on
  443. 18:21client event and it's going to look like
  444. 18:24and it's going to look like this we're
  445. 18:25going to say greet player. on client
  446. 18:30event colon connect function open
  447. 18:34parentheses close parenthesis and we'll
  448. 18:36hit enter now you might notice we're not
  449. 18:38required to pass in a player argument
  450. 18:41because we already know which player
  451. 18:44we're trying to send the message to so
  452. 18:47this this does require a little bit of
  453. 18:49practice to understand like the
  454. 18:51different parameters what is required
  455. 18:53what's not required but as long as you
  456. 18:56understand it I think it'll make sense
  457. 18:58so in this case let's actually pass in
  458. 18:59an argument uh we're going to create one
  459. 19:03argument here that's basically going to
  460. 19:05be the message so we'll say message as
  461. 19:08our second parameter to our fire client
  462. 19:11call uh so the first argument is going
  463. 19:14to be player and then we'll space it out
  464. 19:16with a comma and we're going to pass in
  465. 19:18a message we will say hello new player
  466. 19:23that's going to be our message that
  467. 19:24we're going to pass into the client and
  468. 19:26so it's going to be passed into here so
  469. 19:28now what we'll do is we're going to
  470. 19:30create a text label that we will use to
  471. 19:33greet the player so let's click the plus
  472. 19:35sign and let's add in a text label and
  473. 19:38we're going to call this label
  474. 19:41greeting and let's move this over here
  475. 19:45let's scale this up a little bit and
  476. 19:47Center it down here let's uh let's
  477. 19:51autoscale the text with text scaled and
  478. 19:54let's go back to the local script and
  479. 19:56let's first make reference to our
  480. 19:58greetings text label by by dropping a
  481. 20:01line and we'll say
  482. 20:04local greeting label equals
  483. 20:08guy. greeting and now what we'll do here
  484. 20:11is we're going to say greeting label.
  485. 20:15text equals message all right so now
  486. 20:19this should work as soon as we join the
  487. 20:21game then this text label should be
  488. 20:23updated to the message that we specified
  489. 20:27so as you can see the text label has
  490. 20:28been updated to hello new player because
  491. 20:32when the player joined the game we
  492. 20:34called fire client to that specific
  493. 20:37player and we gave it a message here we
  494. 20:40passed it into here as an argument and
  495. 20:43we changed the greeting labels text to
  496. 20:46whatever the message was and in this
  497. 20:48case the message was hello new player we
  498. 20:50could be even more specific by
  499. 20:53concatenating this message with the
  500. 20:55player's name so we will say hell hello
  501. 20:58new player but instead of an exclamation
  502. 21:00point we will put in a colon and we will
  503. 21:02use string concatenation to add in the
  504. 21:04player name uh to create a customized
  505. 21:07message and the way combining strings
  506. 21:10work is by putting in the two uh Dots
  507. 21:13here and then we're going to put in
  508. 21:15player. name we're going to get the name
  509. 21:18of the player we're and pass it into
  510. 21:21this string so it's going to say hello
  511. 21:24new player colon and then the player's
  512. 21:26name which in this case it's brawl
  513. 21:27battle so let's go into the game and hit
  514. 21:30play again so now it says hello new
  515. 21:32player brawl battle because brawl battle
  516. 21:35is my name so it's going to give out a
  517. 21:38customized message for each individual
  518. 21:41player whenever they join the game for
  519. 21:43the first time all right and the final
  520. 21:44event we will talk about with remote
  521. 21:47events is called fire all clients and
  522. 21:50this is useful if we want to go if we
  523. 21:53want the server to send a message to
  524. 21:56every single player inside of the game
  525. 21:58game so this is very useful for let's
  526. 22:00say round based uh round based Roblox
  527. 22:03games where it's like if we had uh let's
  528. 22:06say a status bar up here that says
  529. 22:09there's a current game in progress or um
  530. 22:12we're about to be teleporting all the
  531. 22:14players to the new map like you kind of
  532. 22:16get what I mean right murder mystery 2
  533. 22:18and a bunch of other round based games
  534. 22:20do this where they have a status label
  535. 22:22that tells us the status of the current
  536. 22:24game um and it notifies and it updates
  537. 22:28for every single player so that's
  538. 22:30similar to what we're going to do uh
  539. 22:32with fire all clients we're going to
  540. 22:35make a global announcement that will
  541. 22:36show up for every single player up here
  542. 22:39and we will do that first by creating
  543. 22:41another text label so let's duplicate
  544. 22:44our greetings um text label by hitting
  545. 22:47contrl D and we will move this up here
  546. 22:50all the way at the top and let's rename
  547. 22:52this to
  548. 22:55announcement and let's change the text
  549. 22:57label to
  550. 22:58Global
  551. 23:00announcement and what we'll do is we're
  552. 23:04going to hide this for now by clicking
  553. 23:06on by unchecking visible so whenever the
  554. 23:09server fires to all the clients we're
  555. 23:11going to make this announcement label
  556. 23:14visible so now let's create another
  557. 23:16remote event over here in replicated
  558. 23:17storage so let's just create a remote
  559. 23:20event let's rename this
  560. 23:23to announcement that's what we're going
  561. 23:26to call it or no actually let's let's
  562. 23:28make it more specific let's say give
  563. 23:29announcement so now what we'll do is
  564. 23:32we're going to go to our leader stats
  565. 23:34and let's make reference to our give
  566. 23:37announcements remote event so we'll say
  567. 23:39local give announcement equals game.
  568. 23:43replicated storage. give an oh give
  569. 23:48announcement we're going to wait about
  570. 23:5020 seconds before a global announcement
  571. 23:53will be sent to all the players that are
  572. 23:55inside of the game so we're going to put
  573. 23:57put in a task. weight function here with
  574. 24:01about 20 seconds and then what we'll do
  575. 24:04is we're going to fire the give
  576. 24:07announcements remote event to every
  577. 24:09single client and it's structured like
  578. 24:12this we'll say give announcement colon
  579. 24:16fire all clients and you might have
  580. 24:20noticed that we don't need a player
  581. 24:22argument here because we know that for
  582. 24:25this we're going to pass it to every
  583. 24:27single player in the game so we don't
  584. 24:29need to specify uh which player but we
  585. 24:32can still add in more arguments into
  586. 24:35here uh like usual so now what we'll do
  587. 24:38is we're going to catch this uh down
  588. 24:40here into our local script and what's
  589. 24:43really interesting here is that the
  590. 24:45syntax is exactly the same uh for if
  591. 24:48we're just communicating from the server
  592. 24:51to one player because this works the
  593. 24:54same way if it's being sent to each
  594. 24:57indiv idual players so it's essentially
  595. 24:59the same thing here let's first go back
  596. 25:00to our script let's copy our
  597. 25:04announcement and let's paste it down
  598. 25:06here and then we will say give
  599. 25:09announcement. on client event colon
  600. 25:13connect function and then we have no
  601. 25:16arguments here so we'll just we'll we'll
  602. 25:18just drop to the next line and then what
  603. 25:20we'll do is we're going to make our
  604. 25:23announcements text label visible so that
  605. 25:26all the players can see this
  606. 25:28so what we'll do is we're going to say
  607. 25:31GUI do
  608. 25:33announcements Dov visible equals true so
  609. 25:38this one line will make this
  610. 25:40announcement text label visible to every
  611. 25:43single player inside of the game so now
  612. 25:44you might ask how do we know if this
  613. 25:46works inside of studio if we're trying
  614. 25:48to test out um fire all clients because
  615. 25:51we need to know if this works for at
  616. 25:53least two players Roblox has actually
  617. 25:56provided us a great way to test um our
  618. 25:59Roblox game with multiple players if we
  619. 26:02need more than one player to test the
  620. 26:04game because what we've what we've been
  621. 26:06doing is we've just been simulating
  622. 26:08playing solo inside of a Roblox game but
  623. 26:10what if we wanted to create our own
  624. 26:12server our own local server to test
  625. 26:14multiple players at once we can actually
  626. 26:17do that with a feature Roblox has
  627. 26:19provided for us um by going over here to
  628. 26:22test and there should be a little
  629. 26:24section here inside of clients and
  630. 26:25servers where we can create a local
  631. 26:28server with however many players we want
  632. 26:31but make but in this case we're going to
  633. 26:34use two players and essentially what
  634. 26:35we'll do is we'll press the start button
  635. 26:38and what will happen is that Roblox will
  636. 26:40give us three Windows one is the server
  637. 26:44and the other two are each of the
  638. 26:47players so let's hit start and see what
  639. 26:50happens so what we should see is one
  640. 26:54window that rep that represents the
  641. 26:56server and there's two more windows that
  642. 26:58are showing up so one of them is player
  643. 27:00one and the other one is player two
  644. 27:02because we made a local server to play
  645. 27:05test as two players so now that we're in
  646. 27:08the game we can see that we have player
  647. 27:11two over here and we have player one
  648. 27:14over here so this is how we're able to
  649. 27:17play test a game with multiple players
  650. 27:19by creating our own server to be able to
  651. 27:21do that and as you saw uh I I don't know
  652. 27:24if you actually did see it but around
  653. 27:26the 22nd mark the global announcement
  654. 27:29was sent to all the players so both of
  655. 27:32our players at the exact same time I
  656. 27:34don't know if you did catch that you can
  657. 27:35like rewind it for like about 10 seconds
  658. 27:37but it is what happened the server after
  659. 27:40about 20 seconds has sent the global
  660. 27:42announcement message to every single
  661. 27:45player that was inside of the game to
  662. 27:47tell them to make this text label
  663. 27:49visible and we were able to successfully
  664. 27:52do it uh at the exact same time so
  665. 27:55that's just another very useful uh
  666. 27:57function to use whenever you want to
  667. 28:00whenever you want to send a message to
  668. 28:01all the players inside of the game and
  669. 28:03so if you want to stop this play test
  670. 28:05session with all of these different
  671. 28:06Windows uh you can just go to test and
  672. 28:08then hit cleanup to get rid of all of
  673. 28:12the the windows that are on screen and
  674. 28:14sometimes uh it doesn't get rid of all
  675. 28:16of them so you just have to manually X
  676. 28:18out of them which I don't think should
  677. 28:20be a problem now you might ask can't we
  678. 28:22just get a table full of all the players
  679. 28:24and just manually use f client for every
  680. 28:28single player yes you can do it that way
  681. 28:31but why would you want to put up with
  682. 28:32the struggles of having to do all that
  683. 28:34when you can just do it all in one line
  684. 28:36I think uh Roblox has realized that this
  685. 28:38is a very common use case which is why
  686. 28:41they made this into a separate event
  687. 28:43rather than having you constantly fetch
  688. 28:46a table full of all the players inside
  689. 28:48of the game and then just manually
  690. 28:51putting and just manually using fire
  691. 28:53client for every single player so that's
  692. 28:55why we could just do it all inside of
  693. 28:57one on line with fire all clients rather
  694. 28:59than having to do it uh individually to
  695. 29:02finish off let's review what we just
  696. 29:03learned with ver mode events so and
  697. 29:05again this can be found inside of the
  698. 29:07Roblox Dev Hub so I'll leave a link to
  699. 29:09that in the description if you want to
  700. 29:10take a closer Deep dive into it there's
  701. 29:13three ways of communicating from the
  702. 29:15server and client with remote events the
  703. 29:17first one is from the client to the
  704. 29:19server and basically how it works is
  705. 29:23that we have a we have a local script
  706. 29:27that uses the fire server function and
  707. 29:30you can pass in whatever arguments you
  708. 29:32want inside of this and then the server
  709. 29:35will catch this call by using the remote
  710. 29:38event on server event and the first
  711. 29:41argument has to be the player that calls
  712. 29:44this function no matter what it
  713. 29:45implicitly calls it and then afterwards
  714. 29:48it's whatever arguments you put inside
  715. 29:50of this fire server uh function call the
  716. 29:53second way of communication is the
  717. 29:55opposite so it's
  718. 29:58from the server to the client and this
  719. 30:01is basically completely flipped so from
  720. 30:03the server it calls fire client and the
  721. 30:07first argument has to be the player that
  722. 30:10we're specifically trying to send this
  723. 30:13call to and then anything after that is
  724. 30:15going to be the arguments after the
  725. 30:17player and then it's the and now it's
  726. 30:19the client's job to use on client event
  727. 30:23to take this function call and do
  728. 30:25whatever it wants to do with the
  729. 30:27arguments that we provided into here and
  730. 30:30like I mentioned you don't need to have
  731. 30:32arguments arguments are optional but
  732. 30:34where it says that we need to pass in
  733. 30:36players that is required and so server
  734. 30:39to client is basically the opposite of
  735. 30:42client to server as expected and then
  736. 30:44finally we have a special use case which
  737. 30:47is server to all the clients and this is
  738. 30:51basically the same thing as server to
  739. 30:55client except this is for every single
  740. 30:58client or player inside of the game so
  741. 31:01the only thing different here as you
  742. 31:03noticed client here is the same thing as
  743. 31:07the client here for server and client
  744. 31:09the only thing different is the server
  745. 31:12instead of using fire client and
  746. 31:14specifying the player parameter all we
  747. 31:16need to do is just say fire all clients
  748. 31:19and we can pass in whatever optional
  749. 31:21parameters we need so that's the basic
  750. 31:22rundown of all three functions that you
  751. 31:25can use to communicate from the server
  752. 31:27to the client with one-way communication
  753. 31:30this episode is a bit too long so that's
  754. 31:32why I'm going to continue this in the
  755. 31:34next episode when we talk about remote
  756. 31:36functions and how we can further expand
  757. 31:39upon our communication with the server
  758. 31:41and the client because remote events
  759. 31:43essentially act as a one-way
  760. 31:45communication from either client to
  761. 31:47server server to client or server to all
  762. 31:49clients but in the next episode we're
  763. 31:51going to do two-way communication so
  764. 31:54it's going to take the extra step to
  765. 31:57further our knowledge on the server and
  766. 32:00client field so that's pretty much going
  767. 32:02to be it for this episode join my
  768. 32:03Discord the link is in the description
  769. 32:05and I will see you in the next episode
  770. 32:07take care

About this transcript

This page contains the full transcript of Remote Events (One-Way Communication) - Roblox Advanced Scripting #5 by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 5,703 words across 770 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.