Advanced Roblox Scripting Tutorial #6 - UserInputService (Beginner to Pro 2019)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
all righty guys welcome back to another deaf gang tutorial and guys this may be the most exciting tutorial we have ever had on the channel now you're probably wondering okay well what's it about and you might have read the title but basically we're gonna be learning about the user input service now if you guys don't know what that is it's basically like how you detect if a player press a key so that for example let's say you wanted to make it so whenever I press spacebar I jumped well obviously already does that because that Spence it built into roblox but let's say you know you wanted me to like delete a part whenever I press to eat right they would you know delete the part that's how you basically find out what the player is pressing and how to actually make it do stuff so this is very very cool and I'm so excited to show you guys and yeah it's me pretty fun so anyways guys um sorry about that anyway these guys it's going to get right into toriel but like always be sure to watch the beginner series if you haven't already or else you might be confused so yeah link to that is in the description below but anyways guys let's start okay so first things first the user input service okay now what is the use of input service basically guys by definition the user input service you can you can look at it but basically what it is it's it's like how you detect what the player is pressing okay it's the input service so whatever inputs we're gonna being pressed you can get from that so yeah but the only way you can get the user input service is through a local script so make sure you create a local script so go ahead and make a local script over here in the right-hand corner on the right side and I'm gonna put in the starter player and then started play your scripts and then we actually have to get this service so I talked to you guys about services I'm pretty sure and how you get the service is you just make a variable so we'll name it user input service and then we're gonna make it equal to game dot get service I don't get service and then sorry user input service now let me zoom in a bit cuz hopefully it's easy to read there you go oh crap alright there you go alright so next we wanted to go ahead and actually make it do something okay so now there's a bunch and a bunch of properties for user input service like there is a lot I have the wiki over here my left monitor I'll go ahead and show you guys that real quick but basically guys in the user input service there's like I said a lot of stuff and like many many properties that I cannot go over on one video like I look at all this stuff okay basically this is how you find out if a player tap the screen this how you make it so like your games crowd a little mobile and stuff like that this is a very in-depth service and I cannot cover everything in one video obviously so if you want to actually read up on it which I suggest you should then make sure to go watch this or make sure to go with link in description and I will have the API reference link to you know here right here so yeah I like inscription alright anyways but we're gonna be covering a few of them the most important ones which is if input began and also what the are also at what like key is pressed how to find out of keys pressed so yeah anyways so we're gonna go back here and we'll do this now okay all right so we're gonna start off by finding out how to check if a key is pressed and actually before I do that if we have two one I forgot to mention one thing guys if you if you ever seen you can actually get your keys like find out what key was pressed with a mouse like you know I remember I forget to use a mouse like local mouse is equal to or may give me the player of like local player is equal to game dot players dot local player and then I did remember I did local mouse is equal to player get mouse you can actually do mouse key down and connect a function to it right now don't use this you guys are probably gonna see this one day in some code maybe in a free model you might open it and read this don't ever use this because it's actually deprecated and it doesn't get updated anymore so this is very outdated and I do not recommend you use this it still works like most of the time I'm not sure exactly when it wouldn't work but I know this is not good anymore and there's a way but I do way to do it which is with a user input service now the user input service is a bit more complicated but still it's a lot more lot better okay so don't use this if you don't have to all right that's all I'm gonna say okay now let's go ahead and start this okay so we're gonna go ahead and find out how to detect if a player press something on their keyboard that's it we're gonna find out how to detect if they depress something at all so what we're gonna do we're gonna do user input service and then dot sorry I can't think in foot begin and then connect function boom okay now basically what this means is it's this is an event right and whenever input begins so if a player work okay so let's say there someone on their phone right and they were to tap the screen or let's say something like computer and they press the key on the keyboard or anything like that input began basically I said what it does is it detects if anything or any input starts okay so with this we could just you know obviously prints out you know input begin but we want to find out if they press the certain key so we're gonna do to find that out is we're going to do actually there's there's parameters in here sorry and the parameters you have in here is the input that happens so if a player does something which we know they obviously have to that to put some input in the parameter right there is input and that's how you find out what the input was right and there's also one more event called game processed event now this vent basically means if the game processed it then this will be true so this is a boolean value and this is um think I don't know I don't know what kind of values is but yeah so yeah okay anyway so we're gonna go ahead and do this we're gonna go ahead and do it if and put inputs dot key code is equal to equal to e num dot key code dots okay as you can see here it says all letter trigger will do will do are or okay so that's every single thing I throw out so I should kind of cool now we're gonna do a alright so basically then prints player is pressing player pressed down the a key okay there we go alright guys so basically right now what this little if statement does is it finds out if the player press two eight key which by using the input it got from the events it's going to print this out right now what is enum you guys may be wondering enum I don't really know how to explain it to be honest it's basically just like I don't know I don't even want to stands for to be honest with you guys but I just know that you need to put it there you look that up if you want to but yeah that's that's what it is so if you ever want to change it another key to you can just do enum inah Mexico dot R or f10 as you can see there it said a bunch of key to my progression read this right here but it says like left curly keypad plus all the keys basically on the keyboard even says like a euro and stuff I have my keyboard but anyways that's what it does that's pretty cool well but we'll keep that for a for now and we go ahead and test it out and see if it works so there's one thing I do want to show you too so let's go ahead and run this and press a and look guys look at that okay player press down a key and it keeps okay as you can see there it's printing a bunch of times but doesn't print out you know but there you go see yeah that's what it does so it's pretty cool actually and obviously I'm moving I press it because it's a keeper but um it doesn't fit out there too so basically now I can bind into something whenever I wanted to do I can make it do now if you guys noticed hopefully you ran the script with me if you guys noticed you actually whenever that mom whatever like you press a it only prints it out one time it doesn't keep printing it you have to if you wanted to front again you have to press a again even if you have it held down it won't keep printing it now you're probably wondering well what if you want it to detect if it's being held down like what if you want to know what if you want to know if it the egg is being held down now there's a pretty easy way to do this it's not with an event but I want to show you guys that because that's actually one thing I had a problem with back in the day when I was learning the script so I'll show don't do that right now all right so basically in here if you end user input service you have user input service input begin right now what you also have is you have user input service dot input ended so basically if there's no input happening then this function will run okay now I don't think there's any things in there okay wait another is okay all right so okay okay okay all right so now this is a bit confusing but there's also another thing in here with input ended called input right so that it's the same thing now it's the input that ended so I asked for that pay but basically whatever input ended it's going to be in this little mirror right here right so we're gonna go ahead and do that and this event this parameter is literally optional I don't really use it too much but maybe in more advanced stuff you might but um you have to add this here if you don't want to and sorry about my dog he just I don't know anyways so we're gonna go ahead and do if input dot key code is equal to e num key code a then okay so basically what I'm doing here in this event is I'm figuring out if the input that ended was equal to a right that's what I'm figuring out so yeah now basically how we can check if it's being held down is what we can do is make a variable up here because if I put it in here it won't be out here at all right so I didn't make it in here cuz this is out of the scope of there so I hope you guys remember that anyways so we're gonna make a variable called a key a key pressed okay so equals false okay so right now basically if the a key is pressed then we're gonna make this variable true okay so true and then we're going to make this variable false because obviously the input ended here and the end of them again here so now we can print out what it's doing and in a loop so we can do while a key is true I don't know wait I wanna make E is equal to true do we'll do it we'll do a weight cuz i dont want it to crash an excellent I'm gonna press a key is being held down so now basically as you can see here if I had press a and you know I'm doing input it something is gonna make this true or if I let go of it to make us false so that is how this event runs as you can see here if this is true then this event will run so let's test it out real quick and make sure it works and actually I don't who's gonna work okay no it doesn't work I don't know I know just why actually alright so it didn't work now why didn't you worry about wondering okay so basically the script ran through this event right well you know whenever roblox reads a script right there or the computer reads the script it just reads right through it and the events it'll actually wait for because it's an event but the while loop it already read and it passed it right so basically what that means is it skipped it and the a key was down and it was true but it already read that so it didn't go back to it now what would you do to fix that is actually put this inside of the input began thing right here so what we can do is this right here and there we go and now basically whenever the input is happening right now or the you know the infant began ads again see here while a keys press is equal to true and you can do this so now it should work I'm pretty sure here we go and yep see I'm holding down right now and as you can see there it is printing it out a bunch of times I'm not sure being read there's like a little number beside it but um it's printing it out 181 200 times 240 250 yeah basically get the point there hopefully and yeah that's basically what it does so hopefully that makes sense to you guys that's how you detect if something is being held down which is pretty useful I'm gonna you guys might use that one day which you actually probably will but um yeah all right now guys we're gonna show you one more cool little example and a practical use for input service which I'm sure you can think of some practical use for it but I'll just show you anyways cuz it's pretty cool so yeah here we go also one more cool event I want to show you guys too is you actually check if like if it's a keyboard pressed at all actually check that too you can do like I'm gonna show you you can do if and let me delete this real quick you can do if user input type are now so if input user input type basically like input is equal to e num dot user input type dots keyboard so then prints player pressed key and then we can concatenate it we can make the key one of the input key code there you go all right now basically what this will do is print out the key that pressed but basically there's a if statement right here it text in a text if a player you press the key on the keyboard at all and if it did that way you know it did so let's see if it works so oh okay I didn't not concatenate right that right okay what am i doing anyways you get the point though that's what it does that I got a concatenation here but um yeah anyways that's what it does you can print out a key right here actually you don't let a little fix it real quick okay there you go see it print up the key right there prints it out what it is and now that's pretty cool so basically if you wanted to find out like you know like what the key was I'm pressing all the keys my keyboards is so cool I don't know all these keys on here that's actually really cool oh crap okay anyways that's pretty cool so yeah alright so now if you wanted to find out if player was afk or something you could you know do that and I don't know it's a lot more stuff to that but yeah like I said guys please be sure to read up on that and yeah but anyway this Liberty u ends I want show you a more practical use for it now I know this is a pretty long tutorial I'm sorry but it's really cool too so yeah anyways we're gonna go ahead and do something cool which is we're going to make we're gonna make a part in here okay like a part and we're going to delete the part if we press Delete on our keyboard okay so if you press Delete on our keyboard the parts didn't delete so let's try it out real quick so we're gonna do if input dot key code is equal to e num dot key code dot deletes then game dot workspace top part and then destroy all right pretty simple stuff we can watch it delete and here we go guys so let's load in alright guys take a bite of the part and delete it that's so cool I don't know why I feel like that's so cool it's like I don't know man but anyways that's pretty much what it does and yeah I hope you guys enjoy this tutorial if you did like always be sure to leave a like and like I said guys be sure to read up on as well cuz there's a lot more and usually input service I didn't explain in this video cuz I would be way too long and I cannot cover all of it but um yeah that's pretty much it guys I hope you enjoyed the video like always be sure to record server and link below and if you have any questions be sure to ask there or the comment section and yeah alright guys I'll see you next tutorial hope you do this one and also guys just one more quick thing I'm going to be doing a live like a some kind of live it's like development session maybe where we can have like a game jam I don't know man but I want to do some live streaming where I can answer your questions like live I'm not sure any beautiful I'd get to be honest but I'm gonna I'm gonna think about time to do I'll let you guys know when but um yeah anyways hope you enjoy the video and actually that ten times already but also we're going one more quick thing okay guys listen listen listen so you can make like so much cool stuff you can make lick it like a you know like you can you can make pretty much anything now I mean you have the key pressed and you have the mouse so you pretty much want to do anything also guys you actually get that Mouse with the user input service to what you can look into that if you want to but yeah alright I'm sorry I'm trying on so long it's just like so exciting for me and I'm just I'm excited to tell you guys okay I'm sorry anyways I'll see you guys the next one for real this time okay good luck have fun guys bye
Info
Channel: TheDevKing
Views: 86,651
Rating: undefined out of 5
Keywords: TheDevKing, Roblox Scripting Tutorial, roblox, studio, coding, tutorial, userinputservice, userinputservice roblox, userinputservice mouse roblox, keydown event roblox, how to find out what key was pressed roblox, how to detect a keypressed in roblox, roblox studio userinputservice, robox userinputservice, E to pick up roblox, e to pick up tool roblox, how to find out if a key was pressed roblox, roblox coding tutorial, roblox programming tutorial, how to code in roblox, RDC 2019
Id: 4z1HVwe0sLE
Channel Id: undefined
Length: 15min 59sec (959 seconds)
Published: Sun Aug 18 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.