Advanced Roblox Scripting Tutorial #8 - Remote Events & Remote Functions (Beginner to Pro 2019)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all righty guys it's the Deaf can hear back with a brand new video and guys welcome okay in today's tutorial I'm gonna be teaching you about remote events and remote functions so yeah it's gonna be a bit of a confusing one okay for some people a lot of people actually have a lot of trouble with this but I'm gonna explain it the best I possibly can I remember exactly what I had trouble with whenever I first learned it so that shouldn't be a little you know maybe I can clear things up for you that you know a beginner also would because I was once a beginner too you know I'm saying so yeah anyways let's go ahead and start alright so I have two notes over here to the right so if I pause for a second and think that that's why so yeah okay so first of all remote events and remote functions okay you've probably heard of them before and but you know what are they okay that's probably what you're wondering what are they and actually before we get into the video I forgot to say please be sure to watch my beginners series scripting tutorial or else you will you'll be very confused okay this is not as a total you want to just jump right in to go watch the beginner series first the link is in the description below so yeah and anyways I'll start okay so remote functions now what are they okay so basically by definition remote events and functions are used to let scripts on the server in local scripts on clients to communicate with each other okay so what does that mean it basically means you know how roblox added filtering able to their games which every game had filtering enabled now hopefully you watch the tutorial if you didn't a lot of deadly encryption as well but filter enable guy shouldn't know what that is by now but basically it means that anything that happens on the server will replicate and everyone on the game will see it but if it happens in the client so like for example if a part is gets deleted in like a client so if I were to do okay well basically if I were to make a part right now right and I grab now I did local part is equal to game now workspace top part no threat this right now and then I did part destroy only I would see it or yeah only I would see it you know because that's why because hey the reason why is because I did it on a local script and a local script only happens for you and anyone in the server who didn't run the local script will won't see the parts deleted the part will still be there for them so yeah hopefully you guys to understood that filtering enabled toriel I made so you definitely go watch that if you haven't already the lakes in description so please watch that first if you have it but um yeah okay anyways now what are motor functions do or remote events do so remote events basically make it so you can actually do stuff from a local script like for example let's say you wanted to have this part destroy in a local script right but you wanted to happen for every one you wanted that you wanted like to go to the server as well how you do that is with remote events and remote functions so what I would do is you sort of mode function so let's go ahead and restart delete all this stuff and and then I'll show you how to do that so yeah and let me see if I have anything written down so yeah okay so here's some practical use for remote events I'm gonna show your motor vents first and then I'm gonna show your motor functions they're pretty similar but there's one slight difference between the two and there's one reason why should use one or the other so yeah anyways let's go ahead and start finally okay okay so first things first we're going to create a remote event and we're gonna put it in the replicated storage the reason why we put it in replicated soared over here is because that way both the server and the client can both access it to both the computer and like you know the server that roblox host is that way both Nick and they can both access it so we're gonna put it in here and I'm gonna make a remote event and then we're gonna name it deletes part okay so what we want to do is we're gonna make it so whenever we delete a part on our on our server arm I mean our client it's gonna delete on the server too because we're gonna send a message to the server saying hey delete this part for everyone else too so yeah alright so we're gonna go ahead and define the local we're gonna we're gonna go ahead and find the replicator storage so to replicate of storage is equal to game get service our get storage so that's getting the service which is you know replicate of storage and a pretty people use rep storage sometimes or they use like RS for replicated soared for short I'll just do a look at the storage just to keep it simple and that way if we confuse you can understand that so yeah anyways we're never gonna go ahead and get the event so we're gonna do local delete part which is the event when we named it we're gonna your locally part is equal to game or sorry replicate a storage dots delete part and actually it will do wait for child's so that way it gets unloaded right away we can have it here so yeah I doesn't give a shift in air alright anyways so now what we want to do is we want to delete the part right on this script but I actually want to use your user input service too so it makes more sense so you should know what user input services and how it works I'm in tutorial on that so hopefully you watch that already but anyways we're gonna go ahead and make it so when we press the our key on our keyboard or the directions you know when you press the delete key on our keyboard it deletes the part on our not only our are not only on our screen but on everyone else's as well so I know way to test that as well which I'll show you guys in a bit so we're gonna go ahead and do actually we're gonna get the user input service to so we're gonna use an abbreviation which is U is which stands for user input service and then we're gonna do game get service user input service and sorry if I talked a lot I just want to want to keep it clear but yeah and then we're gonna do you is dot input began connect function input and then there we go okay so now basically if any input begins and like a key is clicked or the mouse is clicked this events gonna run and then we're gonna do if input or no if wait-wait-wait-wait leave me a sec I need to think okay if yes if inputs dot key code is equal to e num key code dot delete then print delete key pressed and then okay look he pressed and then delete parts okay actually all for that second alright so basically what this means is I'm going to go ahead and do if input key code so what you guys should know what this means but we don't all it's been a real quick so if the input that's press so if the key that's pressed is delete which is a key on your keyboard so if this is pressed then it's gonna print this out which is just for just for right so we can see it in the output and see something and then we're going to have to actually run the event so how do we do this okay so how we run events is by using as by doing this okay so we're gonna go to the aah bleep routers real quick so I can show you we're gonna do fire scrap remote event okay so if you don't know I get the object browser go to view click object browser and yeah anyways remote event okay so what we want to do is we want to tell our server to run this script okay so how we do that is with the arm is with the fire server function okay so what is does the syntax is just this it's the event the name of the event right and then : fire server right and then you got to put parameters in here which is what part do you want to delete which is the part we have in our workspace so we'll just put their part and that's only about we need our only parameter we're gonna put in there so yeah basically now we're going to fire to the server or like tell it we're gonna say hey here's this event we just we just ran the event and here's this part we don't know what you want it you know like and then we have to go on the server script and actually do stuff with that event okay so now we actually to do this and you know figure this out we need to actually go into our server scripts let's make a server script and actually before I do that but basically guys what would happen right now is if I wanted to do this right but only for me I would just do part destroy right and this would work but it would only happen on my screen and not everyone else is in the game so yeah hopefully makes sense alright anyways delete part of our server part and now we're gonna go and make a script in our in our storage okay so how we do this is we can put it in the workspace or we can put it in the server script service server script service is just like a place where you can put scripts right so we'll put it there because it looks nicer it's for more like organized so going extra script in there we're gonna call it we're gonna call it this server script okay that way it makes it clear but this is in the server okay now we're gonna go ahead and do first of all we need to gather up we need to get our event in this script as well because we have to define as variables again so what we'll do to make it quick and simple is we'll just copy out over from this script okay there we go and then we're going to go ahead and actually do it alright so what we're going to do now is we want to do user or not sorry what am I saying we want to do delete part which is the event the name of the event on server events fire of cabinet on server events player and then part ok what did I just do here ok well first of all I mess up the syntax oh but that was wrong I need it's it's an event so um you put the connect thing there put the connect function there we go ok so what does this do here alright so basically on server event so when the server is fired so after this is ran right what's gonna happen is it's gonna go okay the server's fired and then it's gonna go woo into the server script and then it's gonna go right to here skip right to here and then it's gonna anything that happens right here will be well you know will happen okay so will write whatever we wanted to do here and now what you know we know which part we want to delete which is this part right and then you have to put player here because by default that the the on or no you're the fire server event thing the fire server thing right here it actually sends the player as a the first parameter by default you can't turn that off so what you have to do which is on the server event hope you can read that you know the first variable or the first parameter is player okay so you're gonna need to put player here or you can put whatever you want but it's gonna be the player so if I were to delete this it would actually you know the script would actually think this is the player it would think it's named part instead that because we can make it whatever we want we can make this you know bad part or whatever we want but that's what would happen so yeah so just put player there that way always you're gonna put player there and then your whatever parameter you put across it's gonna be there or if you don't have a parameter you know maybe just have player so yeah anyways now we're gonna go ahead and do part destroy okay guys so after all of that we can finally deter the part and here we go oh crap why don't I just do that alright so now here we go and we're gonna go and hit play and now if we hit delete it's going to leave the part for us so let's go and test it out real quick here it is and delete okay I put the syntax error sorry about that I put just oi the story I meant to put destroy okay my bad guys anyways there we go let's do it again and now if we look at it and hit delete it deletes and not also what's cool is if we go ahead and do it on the server so I'm gonna make a test server okay how you do that is by going over here to test and then you go to local server and then you have two players just so we can like people the other people are in the game simulation you know love to clients and then we hit start and then it's gonna make it all for us let me show you I mean alright so basically I'm gonna prove to you that now if I do it or now if I oh crap okay oh crap okay alright anyways I'm gonna prove to you that now whatever happened that's on years are gonna happen there all right so this is player one okay okay all right guys so there's maybe a little confusing but right now on my left side of the screen okay it's player 2 okay well that's our screens player 2 this is player 1 okay so yeah I'm walking on his screen okay this is because this is this is like two people in one game it's like I have two robots open but really I don't have one right and then right here I have this server it's like I can see everything that's happening so yeah they're moving and stuff this is the server okay so what I'm gonna do is I'm going to delete hit delete on either one of these on clients okay if I hit delete on this client it would delete the part right and if I had to lead on this client or delete the part on this client too right so I'm gonna go ahead and go on my player one right here which doesn't matter which one of this I'm gonna hit delete and boom delete it on my screen and his screen okay and then on the server delete it as well okay so basically if I didn't do the remote event it would only delete on a one person screen so let my short I mean I'm actually to test out for you guys real quick so let me go back to my main thing over here hit cleanup which it'll just closes everything over there and then I'm going to get rid of an offer to leave the script but I'm just gonna change that to not fire the server and what I'm gonna do is I'm just going to make it delete the part instantly okay so watch what happens here we go oh crap charger backup so yeah I hope this makes sense sighs I mean it doesn't make sense please please please leave a comment below ask your questions or join discord server my discord server people and they're always helping left people it's so nice and I'll try to answer you guys as best as I can anyways alright now we're in here we got our part again oh gosh never okay all right here we go we have our part okay so now also I'll show you the server as well okay this is the server is seeing both people and actually go over here's me a little bit cleaner here we go okay and now what we're gonna do is we're gonna hit delete on player - okay player choosing the right over here I'm gonna hit delete okay and then what we're gonna do is we're gonna see if it deletes on this person's screen and it won't so let's watch alright I hit delete and boom it's gone it's gone off my screen but it's not gone off his screen and that's because it's in a local script so it only happens for the person who does it okay so there only happens for the client which was this client right that's another client obviously but you at the point right now if I had to lead on this screen - if I had to lead on my own you know on my left guy over here right he's I see a part over here but this guy he doesn't see that part name because he deleted it right but if I do it now now he's gone for both of us right but on the server right it's still there because this is the server right so we'd only see so that happens on the server it doesn't do the client stuff unless uses something happens on the server so yeah alright guys so hope that made sense to you guys but anyways now I'm gonna go ahead and show you basically how to use your moat function so I promised I'd show you that - so remote functions now what is the difference in the two why do I need to use are more functions than ever more event right they do the same thing pretty much and you know what what's the difference basically okay so like I said earlier remote functions are designed for two-way communication and remote events are designed for a one-way communication so basically remote functions are going to stop running a script until the functions finished running right so until the server side is finished running the client won't Brunning so for example if I if I had here I had a remote function right for example let's say let's say remote function fired here okay wait let me put that at the end of it okay if the remote function fired on this crap if the remote function fired on this line right here anything have an after it so anything like let's say for example I printed hi this would not happen okay this would not happen until this was finished running okay so obviously the syntax are the same but I'm gonna go ahead and show you how they work all right it's pretty similar and pretty simple as well on all so this is here don't worry about this okay anyways so what we're gonna do now is we're gonna go ahead and create a remote function and yeah so let's go ahead and do that we're going to do remote function here we go and we're gonna name it remotes or no delete parts function okay and then we're gonna head and put it up here we're gonna go ahead and name that or define in our script when you have a run script so we're gonna do wrote local replicated or local deletes part function is equal to replicated of storage wait for child and then deletes part function okay now the syntax is pretty similar but a little bit different so we're going to we're gonna go ahead and delete all this stuff right here I should leave that just and then we're going to write out the syntax so it's delete part function which is named our function dot or actually come or colon invoke server okay so that's how you do it it's not fire server but it's invoke server and I can go to the object browser to here and see it so it obvious like I said last time it's going to pass over our player as a first parameter but we want to pass over our parts or gonna put that in there and then we're going to go over here and we're gonna do this first of all we need to actually define it or you had to find out okay I'm here we go and now the way you do the server invoke is a little bit different okay it's gonna be on sir invoke right but what you want to do is you want to do deletes part function on server invoke okay equals now you're punished something equals AK equals function and then player part okay now what this is doing it basically is this is where all the code that is gonna happen whenever you invoke the server okay it's gonna happen right here my ball will blah blah okay right here okay that's there's this word can happen now basically you don't do like you doing an event you don't do delete part function connects you know all that stuff you don't you don't do that okay what you do instead is this and basically you're assigning or you're setting a function equal to the on server invoke so whenever it happens you you run it now you also could do this you could do local on server or on delete part function right you could do equals function or no it's wait what am i doing okay local function is equal or in the name it delete part function right and then we could put the parameters in here as well but the thing about doing this is the fact that if you don't have this the part already which you want or if you actually use it it's gonna give you an error so different me so I wouldn't use this I would just use this right here oh crap and this is these two way to do it by far to alright so we're gonna do the same thing we did last time we're gonna do part destroy and now it should work the same exact way so it's going to test it out and see if it works so I'm just gonna do it in the client okay because it's you know that's how it works so you guys remember and then actually what's cool and what what I can tell you guys to is you see how I'm currently I'm on the client right but if I click this button up here it actually goes to the server so you can actually test that with a nephron to make a whole server and stuff like that so yeah so I'm gonna go ahead and delete and it deleted and boom alright there we go guys we deleted it and it printed hi down there you know past that but um yeah and on the server's leave it as well okay so it did work indeed all right so now what we're gonna do is well we're not what we're gonna do is we're going to I'm gonna test what I said and I'm gonna put a weight in here I'm gonna make it a wait five seconds okay so we're gonna see if it prints hi so after this is a ran we're gonna see the prints I okay because you know the scripts gonna run from top to bottom and it's gonna it's gonna wait until it gets finished or a response technically and and then it's gonna run again so let's test it out it works here we go and okay look it did not fret high yet it didn't pronounce should have right but it's waiting five seconds and then it friend said hi so yeah that's the only difference the only difference between the two really is pretty much just that they both can contact the server and it's called okay wait it's mostly talking they both can contact the server and the clients so there's really no difference in the two but I'm yeah and now one last thing I'm gonna show you or actually one last two things I'm gonna show you it this I notice is a very long tutorial I'm really sorry but it's it's a little bit complicated I guess so it's okay but one more thing I'm gonna show you is how to actually contact the client because I showed you how to reach the server but how do you contact the client from the server so we're gonna do for that is going our server script here and I don't really have a good example for it to be honest with you but what we'll do is most of time when you do that when you do like from server to client communication it's normally when you use a GUI so when you want a GUI to change because all your duis are in your client not on the server so yeah but you don't really usually wife right now so I don't really know a good example but I'm mission to show you how it do it anyways so I'm going to show you it and yeah all right so basically how you do it it's the same thing as invoke client but it's invoke it's like the opposite right so see how you have here for it for remote functions it's just invoke client and then on this local script you're gonna put your gonna do what I did right you're gonna do local crab what am I thinking oh yeah you're gonna do deletes part function on client invoke right equals function and then here you go and also there isn't a player in here right because it's already coming back to you so you're the player right so this isn't there's no like player function or play a parameter in there anymore so like there's here right so the first parameter would be right whatever you sent to it and then here you would obviously do delete part function and then fire server or no not fire so that's that's for the that's for sorry that's for remote functions but for mote or promote events but if remote functions it's going to be delete part function and then server invoke client I'm sorry I think it's confusing sometimes but basically that's how you do it and then for you know for clients it's the other way or for functions is the other way around the same thing right but you have instead of on server an event which we did earlier it's gonna be on client event and then instead of a fire clients gonna be fire server okay so that's pretty much the same thing pretty much hard to do it I would show you guys right now example but I don't really have any but it's pretty much the same thing but it's different syntax so obviously here instead you would just put you would put what what you want it to do and then here you know this is it and then you put the parameter here if you had one right I don't have any examples for you guys because I don't know you guys it on easy why is yet but that's pretty much it now I think I've covered everything guys I'm sorry swirls been so long okay actually the rerecord as a few times because I forgot to mention something so yeah anyways guys that's pretty much it I'm sorry is a little bit confusing maybe like I always you guys if you have any questions please please please do comment them below and yeah that's pretty much it though guys join this course we haven't already and guys coming soon we have a lot more excited tours coming soon I actually did a live stream recently just for fun and it's kind of cool I guess but anyways a lot more words coming soon be excited stay tuned subscribe for your new and I'll see you guys soon alright peace
Info
Channel: TheDevKing
Views: 99,539
Rating: undefined out of 5
Keywords: TheDevKing, Roblox Scripting Tutorial, roblox, studio, coding, tutorial, remote events roblox, remote functions roblox, how to use remote functions roblox, what is a remote event, remote events lua, what is a remote function, roblox remote functions, remote events tutorial, roblox remote events tutorial, remote functions tutorial, roblox remote functions tutorial, roblox studio tutorial, how to script in roblox, how to script on roblox
Id: GwhPXyYKkwU
Channel Id: undefined
Length: 23min 56sec (1436 seconds)
Published: Sat Aug 24 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.