How to make a Combat System: M1s | Roblox Studio

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's up everyone on YouTube this is spark and in today's video I will be showing you guys how you can make a light attack system or an M1 system I will explain everything as best as I can the video will be divided into a few sections and the time stamps for each section will be in the description so if you're ready let's get right into the first part which will be the basic logic of the code so of course in our block Studio we have to deal with both the client side and the server side we're starting off with the structure of the program's client side which is the code happening on the user side meaning the player who's doing the m1's what you see right now on the screen is a flowchart depicting the basic structure of the client's hided code this might be a bit difficult to understand which is why I prepared these charts rewind the video if you don't understand it at any point or ask your questions in the comment section down below so first off we set some variables such as M1 cool down clicked press time and new time M1 cool down is used to make sure you can't use the m1's for a few seconds once you finish off your M1 combo meaning that once I'm done with the fifth M1 you can press the M1 button for a while it won't work so that's basically the M1 cool down the click variable is used to set the minimum delay between each M1 so if someone's pressing extremely fast there will still be some delay between each M1 the code just won't run if that minimum delay has been passed this is done so that the animations don't overlap press time and new time will be used to check the actual delay between each button press done by the user for the first time I press the left Mouse button it'll do the M1 for the first time of course so the combo will be one right so if I press it second time it will calculate the time between the first press and the second press using these two variables all of this will be demonstrated in a bit so now in the code we will first check if the player has pressed left Mouse button if the player has pressed left Mouse button then we will move on to the conditions we will make sure that an M1 is not currently in progress so of course we don't want the animations to overlap as said before so we'll first make sure that's not the case and we will also make sure that the m1s are not on cool down if those conditions are fulfilled then we will move on to the next stage which is execution of the animation setting the click variable to true so that we know that an M1 is currently in progress and sending a signal to the server side so that we can cast a hitbox deal damage and stuff but more on that later on so then if the player presses left Mouse button again the code will again detect it check if the coold down is false and check if the click variable is false if both of those are false then it'll do the second M1 The Click variable is used to set the minimum delay between each M1 as I said before now I'll explain press time and new press time a bit more both of these variables are used to detect the time between each press of the left Mouse button so if the time is less than 2 seconds meaning I did the first M1 and then waited for less than 2 seconds and then did the second M1 we will move on to the next attack but if the time is greater than the second M1 then the m1's will reset and we will go back to the first M1 this will all be the same for the rest of the m1's the only exceptions are the first M1 and the fifth M1 in the code for the first M1 we don't check for the time between clicks because no click happens before the first M1 the only thing different in fifth M1 is that it will need additional code for added knockback back and we will also be setting the cool down to True afterwards additionally we will be setting click to True after each M1 so that the next M1 doesn't run until the minimum delay required has passed again all of this might be hard to understand so rewind the video or ask in the comment section down below so once you've understood this we will be moving on to the next section which is the programming itself starting off for first going to need to create the client script so go and start a player starter player scripts click on the plus icon and just click on local script I've already added one here name it anything you want I've named it M1 script it's going to have this print so delete that so here I've set up some basic variables which are player character and humanoid the player is the user who joined the game the character is of course your own player model the humanoid is what contains stuff like Health jump power walk speed so we might need those later on now we will set up the variables needed for the M1 code which are clicked press Time new press time M1 cool down and also a remote in order to let the server know when an M1 occurs now for the remote we'll go into replicate storage create a folder in here named remotes I've already made one add a remote event name it I'm going to name it M1 script remote so here I've just put the directory for this remote event right here now additionally I'm going to add another variable here which will be called combo I'm going to set it to zero this will be used to check which M1 we are currently on so if you understood the logical part of the code you will know that we will now check if the user has pressed the left Mouse button for that we're going to need to add a service this will be used to detect any and all types of inputs so here we detect whenever the input begins we check if the if game processed event is true if it's true then this code won't run and if clicked is false meaning an M1 is not already in progress and m1's are not on cool down then this code can run provided that the user pressed left Mouse button so it's called Mouse button one once we're here now we'll set click to true so that we know that an M1 is now in progress and we will add one to combo we're on zero right now let's say I press left Mouse button my character does the first M1 but before that it'll increment combo by one so basically that means that we are on the first M1 so that's what this does now we will add the code for the first M1 now here we check if combo is equal to one meaning if we're on the first m one so we're going to need to run the animation here and send a message to the server through this remote that we have just executed the first M1 and then the hit boxes and stuff will be cast on server but for that of course we need to first set up the animations so I have a few animations right here in this dummy I'm going to export those and use them for the code also make sure your animations have a marker called Hit we will be needing that later on copy the ID go to replicate storage and create a folder for your animations create another folder called m1's add an animation here name it one and paste the animation ID which you copied earlier do the same for the rest of the m1's so here I've set up my M1 and animations now we'll go in the code here we'll set up a table so once we've set up this table we can just run the animation here play but before that we're going to assign a value to the variable we created earlier which is press time so this is where we start measuring the time think of it as a stopwatch which we just started running so here we created an Mt connection and stored this in the connection so BAS basically the code here will run when we reach the hit marker which we placed earlier in the animation so we'll just be using the remote over here to tell the server that the first M1 just happened we will send combo to it and that's all the code you need for the first M1 it's just like six lines now let's actually test it out and I'll show you that it works it won't do any damage yet though because we haven't added server side as you can see I pressed M1 and it actually played the animation if I press it again it won't play it again because like we've set click to true but we never actually set it to false so we'll be doing all that later on now let's move move on to the code for the second third and fourth M1 for the second third and fourth M1 we can just set the condition to this we don't have to separately check if the combo is two or it's three or it's four the code for the second third and fourth is the same unlike the first and the fifth one I'll explain the differences later on once we're done with all the code we're going to be assigning a value to new press time so here we started the stopwatch and here we've ended it now we will manually check the time interval between these two now if this is the second M1 this is the first then this is the time between the first and the second press now we only want the next M1 to happen if the time is less than two so that's the maximum delay between each M1 if it's more than this then the m1's will just reset and you'll go back to the first one if it's less we will again start the stopwatch also make sure to disconnect these connections so here as you can see I did not enter two three or four instead I entered combo the combo has the same value as the M1 which were on so which is why this will work and this basically allows us to minimize the code we don't have to add separate conditions for the second third and fourth M1 that would make it too long now we've added Ed the code for what happens if the time is less than two but if the time is more than two we want it to reset so for that we're going to add a function here so if the time is less than two we get the next M1 if it's greater than two meaning we delayed it too much it'll go back to the first M1 so this one right here the code is of course the same so now finally we can move on to the final M1 so most of this code is the same except the fifth M1 will have knock back but that's for the server side the different thing for the client side is that we will add the cool down here I'm going to set the cool down to 5 Seconds M1 cool down equals false and that's all the m1's done now we just need to make sure that clicked gets uh set to false after the minimum delay so whenever this whole code runs at the end of it it will wait for 0.35 seconds it'll check if clicked is true and if it's true it'll set it back to to false so this is what determines the minimum delay between each M1 so like even if it's someone's pressing left Mouse button extremely fast like with 0.1 second delays the m1's won't run that fast they'll run only as fast as the time you've put over here make sure it's not too low otherwise your animations will over overlap and it will mess up the whole thing we also have to make sure that we set combo back to one every time it's reset so it's going to be zero if we've finished the combo it's going to be one if we've reset it and we want to set click to false here as well so now that all that's done let's test it out as you can see the whole combo string is working if I delay too much it goes back to the first M1 let's wait do it again it goes back and if I finish the whole combo I'm clicking and it's not working it's on cool down it works again after 5 seconds so that's pretty much the whole client side of the code complete now we will be moving on to the next section which is the server side so now you're going to want to go on to server script service click the plus icon and insert a new script in here name it anything you want I've named at M1 script so now in order to understand how to start the code on the server side we first need to understand how we're sending the message to the server in order to initiate it this is what we've done right here at fire server we are sending our player to the server as well as the combo count so that the script knows which combo we currently on this is all being done through the M1 remote which we set up right here the reason I've only specified combo here is because the player automatically gets sent to the server here in the server script I've already defined the variable for this remote and now we can get right into the code for the server side so here we use this remote to check for the message which was sent by the client script right here and then we connect it to a function so basically all this code will run when the message is detected as I said before the player is automatically sent so we have to add this argument first and then we have our combo so since the player is defined we use it to obtain the character humanoid as well as the humanoid root part here I've defined the parameters which will be used for the hitbox right here so this is the variable containing the hitbox it's created in workspace this right here is the exact position of the hitbox this is how far it is from our humanoid root part this is the size of the hitbox I've set it to 5.5 Cube and these are the parameters which have to be passed here I def find those earlier so then once this hitbox is cast this Loop runs we Loop through whatever the hitbox detected then we check if the hitbox detected a humanoid root part and bear in mind it won't detect the player's own root part so the one who did the M1 their root part won't be included in this because we added it into the filter descendants in instances so everything under our own character will be ignored this is so only our own opponent takes the damage so if we detect a root part we use it to define the humanoid as well then finally here we use the combo count which we passed earlier if it is anything less than five the humanoid will take the opponent's humanoid will take eight damage and if it's anything else and it can only be five if it's not 1 2 3 4 uh they will take 10 damage and they will also get knocked back so this is the velocity they'll be knocked in the direction which the player is facing and this is the duration of the knockback it will automatically be deleted after 0.3 seconds so I made a small mistake here I pass the players humanoid instead of the opponent's humanoid so just change that to your opponent this is supposed to be less than five so now everything should work fine so as you can see the dummy took damage and on the final M1 it took some knock back as well so this means that our m1's are working fine now we're going to be adding a hit animation as well so I have a hit animation right here I'm going to be using this one just right click on the that save it to Roblox go to applicated storage create a folder named animations I'm going to store it in here paste the [Music] ID now that that's set up we're going to create a table over here so now the animation will run and while we're at it let's add a sound effect as well I have a sound effect right here in SF you can get one from toolbox if you want let's define that first so this is the directory of the sfx I've cloned it so that it can run multiple times I've stored it in the opponent and and this is how long the sfx will last so it will automatically delete itself once it's done running now let's test this all out so as you can see the animation and sound effects are working fine as well the m1's are working as well so now there's just one thing missing from all of this which is going to be stun so I'm not going to show you how you can add stun in this video I'm going to make a separate tutorial on that because I'm going to be making more videos on the combat system I'm going to make a video on heavy attack as well but make sure to leave your ideas down in the comments below make sure to like And subscribe and I'll see you in the next one
Info
Channel: SPARK
Views: 6,485
Rating: undefined out of 5
Keywords: roblox studio, how to make a combat system in roblox studio, roblox, roblox studio tutorial, roblox story, roblox showcase, roblox anime games, roblox yba, roblox memes, roblox robux, roblox giveaway, kreekcraft, strongest battlegrounds roblox, how to make a main menu, dev forum, top bar icons, inventory system, studio guide, roblox scripting, roblox studio mobile, roblox studio making a game, tutorial for beginners, how to make a character select, roblox studio challenge
Id: sw1TiHiqiIs
Channel Id: undefined
Length: 24min 12sec (1452 seconds)
Published: Sat Dec 02 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.