Remote Events (One-Way Communication) - Roblox Advanced Scripting #5 — Transcript
Full transcript
- 0:00hey thanks for stopping by we're going
- 0:02to be creating a bunch of stuff that
- 0:04correlates to server and client
- 0:06communication so that we can create
- 0:08systems that allows us to have more
- 0:10security with our Roblox games and also
- 0:12more robust systems with the things that
- 0:15we decide to create inside of our Roblox
- 0:17games and in this episode I'm going to
- 0:19be introducing two of them which are
- 0:22called remote events and remote
- 0:24functions and with them we're able to
- 0:26create things like this so I made a text
- 0:28label that says would you like to buy
- 0:30this button and I have a button down
- 0:32here that we can press called buy button
- 0:35and this costs 50 coins and up here you
- 0:38can see in my leader stats we have 50
- 0:40coins to be able to buy this so let's
- 0:41see what happens when I actually press
- 0:43it so essentially when I press this
- 0:47button it communicated to the server to
- 0:49check whether I had 50 coins or not and
- 0:51if it did then it will then it would
- 0:53subtract 50 coins from my leader stats
- 0:56and it would tell us the message that
- 0:59the purchase has been been successful by
- 1:01updating this text label if we press it
- 1:03again now that we can't afford it uh it
- 1:06will check again but this time we can't
- 1:09afford it so the server will tell the
- 1:11client that the purchase has failed I
- 1:14want you to understand what goes on
- 1:17behind the scenes when we're
- 1:19communicating with the server and client
- 1:21and why this matters a lot when we're
- 1:23dealing with security and exploitation
- 1:26and all those other sorts of things but
- 1:28before we start implementing let me show
- 1:30you something else all right let's think
- 1:32about this for a minute so if you saw
- 1:34one of my previous episodes you might
- 1:35find this diagram to be familiar and yes
- 1:38this is the server and client model uh
- 1:40found on the Roblox developer Hub that's
- 1:43because in this episode I feel like this
- 1:46really ties back into what we're going
- 1:48to be doing inside of this episode so if
- 1:50you remember the game consists of two
- 1:53sides you have the server and the client
- 1:55the server up here is basically the
- 1:58perspective of the game
- 2:00that has access to everything inside of
- 2:03the server and also in the client but if
- 2:06you're a but if you're one of these
- 2:08clients attached to the server also
- 2:10known as The Players so we have player
- 2:13one down here and then we have player
- 2:14two and then player three all within
- 2:17their own perspectives of the game do
- 2:19not have access to whatever information
- 2:22is in the server the server is the
- 2:24PowerHouse of all its valuable
- 2:27information that the client cannot not
- 2:30simply access just freely that's why
- 2:32there has to be communication between
- 2:35the server and the client whether that
- 2:37would be from whether that would be from
- 2:39this player so let's call this player
- 2:40one if it wanted to send information to
- 2:43the server then we will use a remote
- 2:46event to be able to tell the server we
- 2:48wanted to do something and it'll do it
- 2:51for us or if we have information to a
- 2:54specific player from the server we will
- 2:56go from the server and we will send
- 2:58information to a specific player play
- 3:00like let's say player 2 to tell them
- 3:02that they to tell them that they got a
- 3:04notification or something or if we're
- 3:06playing a round based game then we will
- 3:08have the server replicate to all the
- 3:11players inside of the game that if this
- 3:14is a round based game that the game is
- 3:15over and it's going to reset everything
- 3:19to wait for the next game to happen so
- 3:22there's so many use cases where we would
- 3:24have to communicate with the client and
- 3:27the server to get stuff done to make
- 3:29systems robust to make it very secure
- 3:32from hackers because that's one of the
- 3:34main important things we need to know
- 3:36about here is that even if it's not for
- 3:38security there's a lot of things you
- 3:40can't do unless you know how to
- 3:42communicate with the server and client
- 3:43so that's why it's very important to
- 3:46understand how this stuff works when to
- 3:47use it and why you should use them and I
- 3:51hope this gave you a little more insight
- 3:52as to what we're going to be doing in
- 3:54this episode now that we understand it
- 3:56let's make some stuff that effectively
- 3:58communicates between the the server and
- 4:00client so first thing we will do is
- 4:03create a leader stats script to give
- 4:05ourselves some coins so we're going to
- 4:08go to the server script service and
- 4:10we're going to make a script and we're
- 4:13going to rename the script to leader
- 4:16stats I'm not going to write all this
- 4:17out uh I'll just like quickly copy and
- 4:19paste a code that I've already had from
- 4:21a previous episode yeah so just to save
- 4:23us a bit of time I created I quickly
- 4:26created a player added event where we
- 4:28created a leader stats fold and we
- 4:30created a coins uh int value with a
- 4:34default value of 50 so that we have some
- 4:36coins to work with um but we're going to
- 4:39basically but basically what we're going
- 4:41to do first is create a remote event and
- 4:44how we can communicate from the client
- 4:47to the server we're basically going to
- 4:48create a button here that says give
- 4:50currency and when the player presses
- 4:52that button it's going to send a message
- 4:54to the server to give our player
- 4:58currency and I me mentioned that this is
- 5:00going to be a remote event so you might
- 5:03ask where do we create this remote event
- 5:05for the most part I would say create it
- 5:07inside of replicated storage I'd say
- 5:09this is the best place to access
- 5:11information that we want to know about
- 5:13from the server and also the client
- 5:16because as you know there are specific
- 5:18folders inside of the game that can only
- 5:20be accessed by either the server or the
- 5:22client for instance server script
- 5:25service and server storage these can
- 5:26only be accessed on the server but
- 5:28things like
- 5:30starter GUI starter pack starter player
- 5:33these things can can be accessed on the
- 5:35client but we want a folder that can be
- 5:38accessed from both the server and the
- 5:40client which is usually replicated
- 5:42storage and replicated first but we're
- 5:44going to put it inside of replicated
- 5:46storage so we're going to hit the plus
- 5:47sign and let's insert a remote event
- 5:51this is what it should look like and
- 5:53let's rename this remote event to give
- 5:57currency so this is what we're going to
- 5:59use to tell the server that we want to
- 6:02give the player currency whenever we uh
- 6:04press a button now let's actually create
- 6:06the button so let's go to starter GUI
- 6:09hit the plus sign we're going to create
- 6:10a screen GUI we're going to then hit the
- 6:13plus sign here and create a text button
- 6:16so here's our text button let's just
- 6:18drag this alongside here so let's change
- 6:22text scale to true and we'll name this
- 6:24text give currency and now let's create
- 6:28a local script inside of the screen GUI
- 6:31so we'll make a local script let's first
- 6:33make reference to the screen GUI which
- 6:36is going to be local GUI equals script.
- 6:41parent and then we'll first make
- 6:42reference to the text button but let's
- 6:44actually rename this text button to give
- 6:48currency so local give button equals GUI
- 6:53dog currency and finally we'll make
- 6:56reference to our give currency remote
- 6:59event which is located inside of
- 7:01replicated storage so down here we're
- 7:04going to say local give currency equals
- 7:08game. replicated storage it's inside of
- 7:12our replicated storage folder. give
- 7:15currency so now that we have our
- 7:16references let's create the mouse button
- 7:19one click event when we press the button
- 7:20so we'll say give button. Mouse button
- 7:24one click colon connect function and
- 7:29then then drop a line down here we want
- 7:31to fire the event so that when we go
- 7:34back to the server we can catch that
- 7:36event when it's being activated and the
- 7:38way we activate this event is by saying
- 7:41give currency which is our remote event
- 7:44colon fire server so when we press the
- 7:48button we're going to fire this remote
- 7:51event to the server and we're going to
- 7:53have the server take this function call
- 7:56which I will show you in a little bit
- 7:57there are multiple arguments we can put
- 7:59in in here but just for right now we're
- 8:01going to leave this empty so now let's
- 8:03catch this inside of the server uh we're
- 8:05going to copy this reference right here
- 8:07so we're going to highlight this and
- 8:08copy and we're going to go to our leader
- 8:10stat script so down here let's drop two
- 8:13lines and let's just control V to paste
- 8:16our copy code and now what we'll do is
- 8:20we will catch this fired event we'll say
- 8:23give currency and it's going to be dot
- 8:27on server event colon connect function
- 8:34and here's what's really important about
- 8:35this so whenever we call fire server we
- 8:39don't pass anything here but indirectly
- 8:42it's automatically going to pass in the
- 8:45player object that called this event so
- 8:49it's going to be our player in the game
- 8:51that called this event when we pressed
- 8:53the button so we're going to pass in the
- 8:55player argument and this is required you
- 8:58have to have the first argument be the
- 9:00player and anything after that is
- 9:03basically just going to be uh whatever
- 9:06arguments we put inside of our function
- 9:09call but for right now it's just going
- 9:11to be player so now that we understand
- 9:12that let's locate our coins in value
- 9:15inside of our leader stats so we're
- 9:17going to say local leader stats equals
- 9:21player do leader stats and then we will
- 9:25make reference to the coins we will say
- 9:27local coins equals leader stats. coins
- 9:31now let's add coins to the int value so
- 9:34we'll say coins. Val plus equals let's
- 9:38just say 50 all right so essentially
- 9:39what we've done is that we created a
- 9:41text button that says give currency when
- 9:44we press it it's going to send a message
- 9:47to the server and it's going to catch it
- 9:50onto the server that we want to give the
- 9:53player that called this remote event to
- 9:56give them 50 coins and I will explain to
- 9:58you why this is important but let's test
- 10:00this out first so we going to go to the
- 10:02game hit test and hit play and see the
- 10:05new button that we just created all
- 10:07right so I've spawned into the game our
- 10:08coins by default is 50 but if I press
- 10:11give currency then it should effectively
- 10:14give 100 coins to the to the player so
- 10:19if we keep pressing it then we should
- 10:21constantly be getting 50 coins every
- 10:23time we press the button so that should
- 10:25be working as expected but now you might
- 10:27ask why do we need need this server and
- 10:29client communication when we're let's
- 10:32say giving currency to a player so in
- 10:34order for me to explain that let me go
- 10:36back into the game and like I mentioned
- 10:38with the server and client model there's
- 10:39you can go between the server and client
- 10:42window by going to test and then hitting
- 10:44this button here uh by telling you
- 10:46whether you're on the server side or if
- 10:47you're on the client side right now I'm
- 10:49on the server side but if I press it
- 10:51again I'm going back to I'm back to the
- 10:53client side so let's see what our coins
- 10:57value actually looks like when we're on
- 11:00both sides of the game so we're going to
- 11:02go to players brawl battle leader stats
- 11:04coins so as you can see my coins int
- 11:07value is 50 like expected let's see what
- 11:10happens if I change the value in the
- 11:13client so if I just change this value to
- 11:17200 then it'll show that my coins have
- 11:20been updated to 200 and my coins in
- 11:23value has also been updated to 200 but
- 11:26what's the problem here it looks like
- 11:27it's working as expected if we go into
- 11:29the server side so if I click our server
- 11:32window and we do the same thing where we
- 11:35and we do the same thing where we go to
- 11:37players we go to brawl battle the leader
- 11:39stats and coins we can see that our
- 11:42value is still 50 despite US changing
- 11:45the value inside of our local client
- 11:48this is why I must reiterate that the
- 11:50communication between the server and
- 11:52client is very important because what
- 11:54you see inside of the client is not
- 11:57going to be replicated to the server for
- 12:00all the other players it's not going to
- 12:02be the same thing so if I had a shop
- 12:04system this actually is not 200 coins
- 12:08but in reality the game says that my
- 12:10player has 50 coins instead of 200
- 12:14that's why when we're updating or in
- 12:16this case giving currency we need to
- 12:18tell the server to give us 50 coins not
- 12:21the client that's why we have to do this
- 12:23whole server and client model with tell
- 12:26with creating a remote event firing the
- 12:28server and then making the server catch
- 12:31this event to then update our coins
- 12:34value because we could have just simply
- 12:36done this inside of our local script but
- 12:38this wouldn't have actually given the
- 12:41player the coins that we want to give
- 12:43the player this would have made us think
- 12:46in the client that we would have that we
- 12:48gave ourselves coins but in reality the
- 12:50game says we did not do anything because
- 12:53this is very easily exploitable for any
- 12:56hacker or exploiter inside of a Roblox
- 12:58game to give themselves a a huge
- 13:01ridiculous amount of coins inside of the
- 13:03game so that they can buy everything
- 13:05inside of the game that's why we rely on
- 13:08the server to do all this for us not the
- 13:11client so I hope this give you a better
- 13:12explanation and a better understanding
- 13:15of why we do these things all right so I
- 13:17mentioned extra parameters being extra
- 13:20arguments or parameters being a thing
- 13:22for remote events and that's what I'm
- 13:24going to show you really quickly here so
- 13:27when we have a remote event it doesn't
- 13:30matter how many arguments we throw into
- 13:31here because we can have as many as we
- 13:33want um this is usually to pass in
- 13:36information to the server um using this
- 13:39remote event if we want it to do
- 13:41anything specific uh it gives us more
- 13:44power to be able to say exactly what we
- 13:46want to do with uh arguments that we
- 13:49pass into to this event call so in this
- 13:53case we have give currency which gives
- 13:55us 50 which gives us a fixed amount of
- 13:59coins every single time we press the
- 14:00button but what if we wanted to specify
- 14:02it on the client um we would do that by
- 14:04creating parameters and passing in
- 14:06arguments to our function calls so we're
- 14:09going to create another parameter here
- 14:11after player by putting in a comma and
- 14:13this is going to be the coins amount uh
- 14:18and we're going to take this coins
- 14:19amount and we're going to replace it
- 14:21with our fixed 50 currency that's over
- 14:24here so now what we're going to do is
- 14:28we're going to go to to our uh fire
- 14:30we're going to go to our local script
- 14:32and inside of this fire server remember
- 14:34that player is implicitly passed into
- 14:38our function call so we actually don't
- 14:40need to pass in player but rather we're
- 14:43going to pass in our coins amount so in
- 14:45this case it's going to be 50 so what's
- 14:48going to happen here is that when we
- 14:49call fire server we're going to pass in
- 14:52our our coins amount and over here it's
- 14:56going to implicitly pass in the play
- 14:58player argument and then our uh coins
- 15:02amount so it's very important to
- 15:04understand that we're not passing in
- 15:05player first this is actually our second
- 15:08argument which is our coins amount but
- 15:10over here we're going to pass in player
- 15:12first thing and then all the arguments
- 15:15afterwards that we uh provided inside of
- 15:18these parameters so if we go back and
- 15:20test it it should essentially do the
- 15:23exact same thing so if you press it then
- 15:25it should do what we needed to do so
- 15:27that works out wonders
- 15:29and like I mentioned uh you can have as
- 15:32many arguments as you want uh as long as
- 15:35you have this player parameter you can
- 15:37have as many arguments as you want here
- 15:39you can pass in as much information and
- 15:41the script will not complain about it so
- 15:43what we just did was we communicated
- 15:46from the from the client to the server
- 15:49but now what if we wanted to do it the
- 15:51other way around what if we wanted to
- 15:53communicate from the server to the
- 15:55client like for instance if if the
- 15:58player has joined the game then we will
- 16:00tell the server to send a message to the
- 16:02client to give them like a special
- 16:05greeting uh through text or something so
- 16:08that's what we're going to do with this
- 16:09example this can also be done by using a
- 16:12remote event so for this example we're
- 16:13going to create another remote event so
- 16:16like I said it's going to be inside of
- 16:17replicated storage cuz that's the folder
- 16:19I recommend putting all your remote
- 16:21events in uh so we'll hit the plus sign
- 16:23and we're going to create another remote
- 16:25event and we're going to rename this
- 16:27greet
- 16:29player and let's go back to our leader
- 16:32stat script so in our leader stat script
- 16:34let's make room for our reference to the
- 16:39Greet player uh remote event so we'll
- 16:41say local greet player equals game.
- 16:46replicated
- 16:47storage. greet player and so and now
- 16:51what we'll do is we'll drop two lines
- 16:53after we create the coins leader stat by
- 16:56saying greet player
- 16:59and you remember how we communicated
- 17:01from the client to the server so we took
- 17:04the remote event and we called fire
- 17:07server but this time what we're going to
- 17:09do is we're going to do the opposite
- 17:11we're going to say colon fire
- 17:15client so it basically does the opposite
- 17:18of fire server it just says fire client
- 17:20instead but here but here's the very
- 17:22important thing we we are required much
- 17:25like our on server event we're required
- 17:28to pass in the specific player we want
- 17:31to send this message to so in this case
- 17:35it's going to be our player which we
- 17:37labeled right here in our player uh
- 17:40variable so we're just going to Simply
- 17:42pass in player so this is the basic
- 17:45Syntax for our fire client event like
- 17:48like I mentioned before you can pass in
- 17:50other parameters if you really want to
- 17:52um but that is totally optional what is
- 17:54required is specifying which player
- 17:57we're trying to send this message to and
- 18:00like with our on server event we need to
- 18:04catch this call onto the client instead
- 18:06so in our local script uh we're actually
- 18:08going to copy our greed player reference
- 18:11and then we're going to paste it down
- 18:13here and then what we'll do is instead
- 18:18of on server event we're going to say on
- 18:21client event and it's going to look like
- 18:24and it's going to look like this we're
- 18:25going to say greet player. on client
- 18:30event colon connect function open
- 18:34parentheses close parenthesis and we'll
- 18:36hit enter now you might notice we're not
- 18:38required to pass in a player argument
- 18:41because we already know which player
- 18:44we're trying to send the message to so
- 18:47this this does require a little bit of
- 18:49practice to understand like the
- 18:51different parameters what is required
- 18:53what's not required but as long as you
- 18:56understand it I think it'll make sense
- 18:58so in this case let's actually pass in
- 18:59an argument uh we're going to create one
- 19:03argument here that's basically going to
- 19:05be the message so we'll say message as
- 19:08our second parameter to our fire client
- 19:11call uh so the first argument is going
- 19:14to be player and then we'll space it out
- 19:16with a comma and we're going to pass in
- 19:18a message we will say hello new player
- 19:23that's going to be our message that
- 19:24we're going to pass into the client and
- 19:26so it's going to be passed into here so
- 19:28now what we'll do is we're going to
- 19:30create a text label that we will use to
- 19:33greet the player so let's click the plus
- 19:35sign and let's add in a text label and
- 19:38we're going to call this label
- 19:41greeting and let's move this over here
- 19:45let's scale this up a little bit and
- 19:47Center it down here let's uh let's
- 19:51autoscale the text with text scaled and
- 19:54let's go back to the local script and
- 19:56let's first make reference to our
- 19:58greetings text label by by dropping a
- 20:01line and we'll say
- 20:04local greeting label equals
- 20:08guy. greeting and now what we'll do here
- 20:11is we're going to say greeting label.
- 20:15text equals message all right so now
- 20:19this should work as soon as we join the
- 20:21game then this text label should be
- 20:23updated to the message that we specified
- 20:27so as you can see the text label has
- 20:28been updated to hello new player because
- 20:32when the player joined the game we
- 20:34called fire client to that specific
- 20:37player and we gave it a message here we
- 20:40passed it into here as an argument and
- 20:43we changed the greeting labels text to
- 20:46whatever the message was and in this
- 20:48case the message was hello new player we
- 20:50could be even more specific by
- 20:53concatenating this message with the
- 20:55player's name so we will say hell hello
- 20:58new player but instead of an exclamation
- 21:00point we will put in a colon and we will
- 21:02use string concatenation to add in the
- 21:04player name uh to create a customized
- 21:07message and the way combining strings
- 21:10work is by putting in the two uh Dots
- 21:13here and then we're going to put in
- 21:15player. name we're going to get the name
- 21:18of the player we're and pass it into
- 21:21this string so it's going to say hello
- 21:24new player colon and then the player's
- 21:26name which in this case it's brawl
- 21:27battle so let's go into the game and hit
- 21:30play again so now it says hello new
- 21:32player brawl battle because brawl battle
- 21:35is my name so it's going to give out a
- 21:38customized message for each individual
- 21:41player whenever they join the game for
- 21:43the first time all right and the final
- 21:44event we will talk about with remote
- 21:47events is called fire all clients and
- 21:50this is useful if we want to go if we
- 21:53want the server to send a message to
- 21:56every single player inside of the game
- 21:58game so this is very useful for let's
- 22:00say round based uh round based Roblox
- 22:03games where it's like if we had uh let's
- 22:06say a status bar up here that says
- 22:09there's a current game in progress or um
- 22:12we're about to be teleporting all the
- 22:14players to the new map like you kind of
- 22:16get what I mean right murder mystery 2
- 22:18and a bunch of other round based games
- 22:20do this where they have a status label
- 22:22that tells us the status of the current
- 22:24game um and it notifies and it updates
- 22:28for every single player so that's
- 22:30similar to what we're going to do uh
- 22:32with fire all clients we're going to
- 22:35make a global announcement that will
- 22:36show up for every single player up here
- 22:39and we will do that first by creating
- 22:41another text label so let's duplicate
- 22:44our greetings um text label by hitting
- 22:47contrl D and we will move this up here
- 22:50all the way at the top and let's rename
- 22:52this to
- 22:55announcement and let's change the text
- 22:57label to
- 22:58Global
- 23:00announcement and what we'll do is we're
- 23:04going to hide this for now by clicking
- 23:06on by unchecking visible so whenever the
- 23:09server fires to all the clients we're
- 23:11going to make this announcement label
- 23:14visible so now let's create another
- 23:16remote event over here in replicated
- 23:17storage so let's just create a remote
- 23:20event let's rename this
- 23:23to announcement that's what we're going
- 23:26to call it or no actually let's let's
- 23:28make it more specific let's say give
- 23:29announcement so now what we'll do is
- 23:32we're going to go to our leader stats
- 23:34and let's make reference to our give
- 23:37announcements remote event so we'll say
- 23:39local give announcement equals game.
- 23:43replicated storage. give an oh give
- 23:48announcement we're going to wait about
- 23:5020 seconds before a global announcement
- 23:53will be sent to all the players that are
- 23:55inside of the game so we're going to put
- 23:57put in a task. weight function here with
- 24:01about 20 seconds and then what we'll do
- 24:04is we're going to fire the give
- 24:07announcements remote event to every
- 24:09single client and it's structured like
- 24:12this we'll say give announcement colon
- 24:16fire all clients and you might have
- 24:20noticed that we don't need a player
- 24:22argument here because we know that for
- 24:25this we're going to pass it to every
- 24:27single player in the game so we don't
- 24:29need to specify uh which player but we
- 24:32can still add in more arguments into
- 24:35here uh like usual so now what we'll do
- 24:38is we're going to catch this uh down
- 24:40here into our local script and what's
- 24:43really interesting here is that the
- 24:45syntax is exactly the same uh for if
- 24:48we're just communicating from the server
- 24:51to one player because this works the
- 24:54same way if it's being sent to each
- 24:57indiv idual players so it's essentially
- 24:59the same thing here let's first go back
- 25:00to our script let's copy our
- 25:04announcement and let's paste it down
- 25:06here and then we will say give
- 25:09announcement. on client event colon
- 25:13connect function and then we have no
- 25:16arguments here so we'll just we'll we'll
- 25:18just drop to the next line and then what
- 25:20we'll do is we're going to make our
- 25:23announcements text label visible so that
- 25:26all the players can see this
- 25:28so what we'll do is we're going to say
- 25:31GUI do
- 25:33announcements Dov visible equals true so
- 25:38this one line will make this
- 25:40announcement text label visible to every
- 25:43single player inside of the game so now
- 25:44you might ask how do we know if this
- 25:46works inside of studio if we're trying
- 25:48to test out um fire all clients because
- 25:51we need to know if this works for at
- 25:53least two players Roblox has actually
- 25:56provided us a great way to test um our
- 25:59Roblox game with multiple players if we
- 26:02need more than one player to test the
- 26:04game because what we've what we've been
- 26:06doing is we've just been simulating
- 26:08playing solo inside of a Roblox game but
- 26:10what if we wanted to create our own
- 26:12server our own local server to test
- 26:14multiple players at once we can actually
- 26:17do that with a feature Roblox has
- 26:19provided for us um by going over here to
- 26:22test and there should be a little
- 26:24section here inside of clients and
- 26:25servers where we can create a local
- 26:28server with however many players we want
- 26:31but make but in this case we're going to
- 26:34use two players and essentially what
- 26:35we'll do is we'll press the start button
- 26:38and what will happen is that Roblox will
- 26:40give us three Windows one is the server
- 26:44and the other two are each of the
- 26:47players so let's hit start and see what
- 26:50happens so what we should see is one
- 26:54window that rep that represents the
- 26:56server and there's two more windows that
- 26:58are showing up so one of them is player
- 27:00one and the other one is player two
- 27:02because we made a local server to play
- 27:05test as two players so now that we're in
- 27:08the game we can see that we have player
- 27:11two over here and we have player one
- 27:14over here so this is how we're able to
- 27:17play test a game with multiple players
- 27:19by creating our own server to be able to
- 27:21do that and as you saw uh I I don't know
- 27:24if you actually did see it but around
- 27:26the 22nd mark the global announcement
- 27:29was sent to all the players so both of
- 27:32our players at the exact same time I
- 27:34don't know if you did catch that you can
- 27:35like rewind it for like about 10 seconds
- 27:37but it is what happened the server after
- 27:40about 20 seconds has sent the global
- 27:42announcement message to every single
- 27:45player that was inside of the game to
- 27:47tell them to make this text label
- 27:49visible and we were able to successfully
- 27:52do it uh at the exact same time so
- 27:55that's just another very useful uh
- 27:57function to use whenever you want to
- 28:00whenever you want to send a message to
- 28:01all the players inside of the game and
- 28:03so if you want to stop this play test
- 28:05session with all of these different
- 28:06Windows uh you can just go to test and
- 28:08then hit cleanup to get rid of all of
- 28:12the the windows that are on screen and
- 28:14sometimes uh it doesn't get rid of all
- 28:16of them so you just have to manually X
- 28:18out of them which I don't think should
- 28:20be a problem now you might ask can't we
- 28:22just get a table full of all the players
- 28:24and just manually use f client for every
- 28:28single player yes you can do it that way
- 28:31but why would you want to put up with
- 28:32the struggles of having to do all that
- 28:34when you can just do it all in one line
- 28:36I think uh Roblox has realized that this
- 28:38is a very common use case which is why
- 28:41they made this into a separate event
- 28:43rather than having you constantly fetch
- 28:46a table full of all the players inside
- 28:48of the game and then just manually
- 28:51putting and just manually using fire
- 28:53client for every single player so that's
- 28:55why we could just do it all inside of
- 28:57one on line with fire all clients rather
- 28:59than having to do it uh individually to
- 29:02finish off let's review what we just
- 29:03learned with ver mode events so and
- 29:05again this can be found inside of the
- 29:07Roblox Dev Hub so I'll leave a link to
- 29:09that in the description if you want to
- 29:10take a closer Deep dive into it there's
- 29:13three ways of communicating from the
- 29:15server and client with remote events the
- 29:17first one is from the client to the
- 29:19server and basically how it works is
- 29:23that we have a we have a local script
- 29:27that uses the fire server function and
- 29:30you can pass in whatever arguments you
- 29:32want inside of this and then the server
- 29:35will catch this call by using the remote
- 29:38event on server event and the first
- 29:41argument has to be the player that calls
- 29:44this function no matter what it
- 29:45implicitly calls it and then afterwards
- 29:48it's whatever arguments you put inside
- 29:50of this fire server uh function call the
- 29:53second way of communication is the
- 29:55opposite so it's
- 29:58from the server to the client and this
- 30:01is basically completely flipped so from
- 30:03the server it calls fire client and the
- 30:07first argument has to be the player that
- 30:10we're specifically trying to send this
- 30:13call to and then anything after that is
- 30:15going to be the arguments after the
- 30:17player and then it's the and now it's
- 30:19the client's job to use on client event
- 30:23to take this function call and do
- 30:25whatever it wants to do with the
- 30:27arguments that we provided into here and
- 30:30like I mentioned you don't need to have
- 30:32arguments arguments are optional but
- 30:34where it says that we need to pass in
- 30:36players that is required and so server
- 30:39to client is basically the opposite of
- 30:42client to server as expected and then
- 30:44finally we have a special use case which
- 30:47is server to all the clients and this is
- 30:51basically the same thing as server to
- 30:55client except this is for every single
- 30:58client or player inside of the game so
- 31:01the only thing different here as you
- 31:03noticed client here is the same thing as
- 31:07the client here for server and client
- 31:09the only thing different is the server
- 31:12instead of using fire client and
- 31:14specifying the player parameter all we
- 31:16need to do is just say fire all clients
- 31:19and we can pass in whatever optional
- 31:21parameters we need so that's the basic
- 31:22rundown of all three functions that you
- 31:25can use to communicate from the server
- 31:27to the client with one-way communication
- 31:30this episode is a bit too long so that's
- 31:32why I'm going to continue this in the
- 31:34next episode when we talk about remote
- 31:36functions and how we can further expand
- 31:39upon our communication with the server
- 31:41and the client because remote events
- 31:43essentially act as a one-way
- 31:45communication from either client to
- 31:47server server to client or server to all
- 31:49clients but in the next episode we're
- 31:51going to do two-way communication so
- 31:54it's going to take the extra step to
- 31:57further our knowledge on the server and
- 32:00client field so that's pretty much going
- 32:02to be it for this episode join my
- 32:03Discord the link is in the description
- 32:05and I will see you in the next episode
- 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.