Roblox how to make a combat system - Roblox combat system FOUNDATION (episode 1)


Transcript: Roblox how to make a combat system - Roblox combat system FOUNDATION (episode 1)

0:00  

Alright guys, welcome back to the Roblox beginner scripting series. Today I'm gonna teach you guys on how to make a combat system. So what I'm so what I want the combat to be is I wanted to have five heads, five punches 12345 The enemy gets knocked back. But first we're just gonna make the animation, we're just going to play the animations and make it print the combos. First, I'm going to need to tell you guys about filtering enabled. So filtering enabled,


0:36  

is a form of anti exploiting. So basically the client can't make changes to the, to the server.


0:44  

All right, so let's give them an example. We're gonna play, we're gonna play in Roblox studio right now. As you can see, we're on the client, the client is basically your computer, your your local computer, and the server is basically on the server.


1:04  

Or I'm gonna remove the script right now.


1:10  

Script.


1:13  

Right.


1:16  

Sorry about that. Or do play right now.


1:22  

It's client, the client of the client is basically your local computer or on your laptop. It's basically the device you're using. And the server is like the server that everyone replicates. So basically, a client is a copy of the server. Okay.


1:43  

So a local script only affects your client, right your device. If you make a local script that damages the damages or enemy, you make their health lower.


1:58  

But if we switch to the server,


2:01  

the health doesn't replicate. Right. But what replicates is the animations. The animations is playing on the client right now.


2:14  

Here's the proof. Goodness.


2:19  

Me,


2:21  

the animations are playing in the client right now. And it replicate to the server.


2:26  

Anything but but that doesn't replicate the position of the character rapidly it's though, let's change the speed


2:36  

to 100.


2:37  

It won't replicate. Let's see.


2:42  

You and I


2:44  

the speed, the speed will rapidly at its 16 fight here is a


2:52  

100. But if we walk right here,


2:56  

the position will replicate. Right? You can't walk this far with 16 speed. So that means the admission, the velocity and the position of the client replicates. So what are we going to do if we can damage them on the client, we're going to use remote events.


3:19  

So basically, when we do something and then we fire the event, the server, the server catches the event and we make the server do something.


3:30  

Let's make


3:32  

the local script in a star pack local script and make sure we get your animations ready. But


3:41  

wait, let me I have made the animations before beforehand.


3:48  

It's a free model animation.


3:52  

Let's load real quick. I'm missing one animation. right


4:01  

let me get the animation report. So what you need to do is basically get the ID


4:20  

let me fix that issue real quick. 65 like you're


4:29  

16


4:34  

Oh yeah.


4:45  

1612


4:52  

Seven


4:54  

looks pretty fine. It's a pretty model animation.


4:58  

Okay, so


5:00  

If you don't know how to save for animations, you need just to export it. And then I'm overriding an animation right now,


5:08  

then you can either save it,


5:11  

and then you need to copy the ID


5:15  

or an animation here.


5:19  

Thank you just paste it right here, you don't need anything else. I'm gonna rename this to punch five.


5:27  

Right, now that you know how to set up your animations,


5:31  

we're gonna make the script


5:34  

gonna call this combat


5:38  

might.


5:40  

First we're gonna call the local peer


5:44  

game players, local player, which means your local player is basically your local player, and local character.


5:57  

later


5:58  

added weight.


6:01  

So it's gonna wait for your character to be added.


6:06  

You don't


6:09  

wait for child


6:12  

character, because your character, your character name isn't going to be kept your name is going to be


6:19  

you've got name, it's going to be your user name. So what we're going to do is to clear up character adequate.


6:29  

Right, it's going to wait for your character, it wait for shoulders and work since you have a unique character in


6:38  

the cumulate works though, since you're human is going to be called cumulate no matter what. Well, unless you use a custom character, and you rename your human, zombie or something, we for child night, we'll make sure your humilate name is already using our custom character


6:57  

unite.


6:58  

And then we're gonna do events.


7:03  

I'm gonna explain this just follows. Then a user interface in good service user input service.


7:13  

User Input service dot input began. So basically, when you're gonna when you when you click


7:22  

your buttons, basically, if you click


7:25  

W or R, it's going to activate this event, no matter what key you press. And if you press W, it'll fire this event.


7:35  

We're going to connect it to a function


7:38  

function. Um, this as Sue parameters, the first parameter is input. The second parameter is game process. So basically, when you're typing or opening a UI, you're on game processed input. I'm going to name this typing, make sure your input is first since


8:00  

the input parameter is first and then the process of typing.


8:05  

Then, if you're, if you're typing, do then return and so you can he can punch while typing.


8:15  

And it's input input right here, input dot user input type


8:25  

dot user type, oops, type, but mouse down then, right okay.


8:34  

When you want to add a input type, when you want to touch if you're clicking news user input type, if you want to detect when a character is pressing a certain button


8:48  

key called input dot key code and m dot key code.


8:54  

D, for example, but we're not doing that right now we're checking if the character is clicking.


9:01  

Then we're gonna be debounce. If the bounce is true, then return and so basically, it's basically like a cooldown, right? When the cooldown is off, the debounce is going to be false. But when the cooldown is on the rebound is going to be true. And when the devout is going to be true, when you click and very both is true, it's gonna return and mean you can't click anymore


9:29  

until very much is false, of course. Okay, so if your debounce is false, meaning you're not on cooldown, we're going to make this on cooldown. Alright.


9:43  

And then all you're gonna do print kit.


9:49  

And then to make it off cooldown, then just wait


9:53  

to 2.1 seconds debounce equals false.


9:58  

So when you're reading your


10:00  

character is using your keyboard, and checks if it's typing or not, when you use your keyboard, if you're typing, then it's not going to work, then check whether or not you click or not, whether or not you use


10:15  

mouse button one, one must mouse button one, or M one.


10:20  

Whether they click or not, then it's going to fire this function.


10:25  

It's not, it's not going to do anything, let's open the output


10:41  

See,


10:43  

this works, this works done, we're just gonna need to make the combo local combo equals one.


10:52  

Okay.


10:56  

If combo equals equals one, then


11:02  

of combo


11:04  

else, combo equals or three, then


11:10  

we're gonna do five hats, it depends on your needs. If you're gonna only have four hits in there, stop at four, you can if you want to have six sets, you can stop at six.


11:24  

Okay, when you hit


11:27  

your mouse, and the combo is one, you're gonna print one


11:34  

and then


11:36  

change the combo to two. And then if you click again, with the combo, it's still then you're going to print


11:48  

just keep doing this


12:01  

and then after this, after your final hit,


12:05  

you want to make the combo reset back to one,


12:09  

you hit four or five times right, it's gonna print five, and then it's gonna reset back to one,


12:16  

then I'm gonna wait for the doe like point, point four seconds and then


12:24  

change the D bones to false. So you can M one again, you won't be able to spam it since school down exists.


12:41  

12345 features back to one. Now that the base is done, we're going to make


12:51  

a remote event by


12:53  

let's what this right here, rename this to combat event.


13:00  

Then we're gonna add a server script. The difference between the local script and the server script is that local script only affects your client. And the server script affects everything. But if you


13:14  

use the server script way too much, it's gonna like lag like crazy server lag is really bad.


13:22  

So we're just gonna


13:25  

define the path to the event combat event


13:31  

script we cobbled combat event.


13:37  

Right?


13:39  

When the combos one is a file server


13:49  

combo


13:52  

so what we're doing is when you click Write, and then once you collect


14:00  

the event will fire to the server, the server script I hear


14:06  

and then it'll send the combo variable.


14:10  

Okay, let's define the event. Script dot parent with a child combat.


14:19  

Event event.on server event on server event means means it's been checked. If any client fires a server and fire server, a server it's gonna connect to a function Connect.


14:37  

function. Right The first parameter is the player is the player and then that sent the event right.


14:46  

The player the first parameter is


14:50  

the player that started the event and then the second parameter is whatever you sent here. Okay.


14:58  

We're gonna do player an undergrad


15:00  

combo, since we think we send the combo, the combo variable,


15:05  

okay, and this is going to be useful.


15:10  

Right, we're gonna count the combo


15:16  

and then we're going to do the same thing


15:36  

show this screen, this screen because it's fired from the server script. If it's below then it's fired from the client.


15:47  

Now,


15:48  

we're gonna make it so the debounce is turned off with the server script. We're gonna make a delay. Delay is basically a weight but under different thread. Let's make an example real quick. If you don't know how it works, you can skip this if you want.


16:10  

This is sweet, right? Wait three print. Hey


16:18  

with three infantry


16:21  

Let's plant


16:24  

Hello.


16:27  

Hello. Wait


16:35  

let's like


16:40  

wait three, right.


16:43  

Print low.


16:46  

And print.


16:49  

Yeah.


16:51  

Let's run


16:56  

it's gonna wait three seconds for Hello. And yeah. So if you want them Yeah.


17:02  

If you don't want them to wait three seconds, for a year. Use delay, right, Les?


17:09  

Three SEC point three seconds function.


17:13  

Print. Hello. So it's going to wait three seconds to print and low. But yeah, it's going to print first because it's on a different thread


17:31  

Yeah, hello. See?


17:34  

Because it's on a different thread.


17:38  

Yeah, it's gonna print first. But if we do, wait, three and print Hello.


17:45  

Yeah, it's neat. Boy, it's gonna take three seconds to print the and I don't want that.


17:51  

You can do delay. Point, three, five seconds function.


17:59  

I'm gonna event fire client.


18:04  

And then we need to put the player here so it knows what client to fire it on. Like, if you don't put a player here, the script will be confused and it will bug out. Since in it know what player you need to send it to me to send it to the player right here.


18:26  

So basically, when you click, click, it'll fire the server. And then it'll get the player and then it'll wait the pointer five seconds and then fire back to the player. Like, click


18:39  

Okay, now


18:43  

we're gonna do an event.


18:46  

It's like I'm Doctor Burbank, but it's on a client event. So an event so it's gonna capture the fire client. Right? It's gonna turn the bounds of events equals to true, then events equals false.


19:04  

You may


19:09  

you may not know what's the use of this, but it's so exploiters can't hack your, your comment script, but you're not gonna use any ones you're gonna use a value that that the client can change.


19:26  

Okay,


19:28  

no, this should work


19:50  

right.


19:52  

See it works and the debounce works okay.


19:56  

Now you check your humanoid and you have an enemy right


20:00  

It's used to play animations. Okay, first we're gonna and then first we're gonna make an animation table.


20:10  

First wooden under wait for child animator. So basically


20:17  

Roblox deprecated the humanoid load animation, because if the animator isn't loaded, it's gonna make a no no Mira and you


20:26  

and it's then there's going to be two animators and your PC will explode. And


20:33  

wait for child enter meter. So the anime, so it doesn't create any more animators. So it's gonna wait until the animator loads and then it's going to load the animations.


20:46  

Then we're going to make the animation tables. And


20:52  

with the animations like this below here.


20:58  

Animator,


21:01  

low animation


21:03  

script,


21:05  

not anonymous. Punch one.


21:13  

So what this is doing is the animator, right? The one below he might the one inside you might, you might, it's gonna load the animation, animations punch one. Oh, yeah, you see this? You see I use this instead of a dot.


21:32  

Because


21:35  

because there's a space, right? And dots don't works on means that has B so you need to do something like this. But if you remove the space, you can just do


21:47  

punch one. But I have a speech right now.


21:51  

Right, we're gonna just gonna load the animations.


21:55  

We're gonna load every single animation,


21:58  

change this


22:02  

and then we're gonna play the animation Adams.


22:10  

Combo


22:13  

play. So what this is doing is basically


22:18  

on the animations, right, the inside the animation table, it's loaded, right, the animations are loaded. And we just need to play. And the combo is basically let's say you have one combo right now. Combo one, right? So basically, animations one, and inside animations dot one is animator, load animation, punch one. So if you do combo, and the combo is still it's basically animations to and the animations which basically learn within punch to.


22:51  

And then so basically, when you click during a fire a server, and when the server gets the message, the animation will play. You can't do this before the Piper server because when you have latency or server lag


23:10  

the animation and server script wants synchronize so that's bad


23:17  

right we just do this


23:21  

and the animation should work


23:43  

see the animations worked this cannot reset back to the to the combo one animations.


23:52  

Right this is the base for the script. I hope you learn something today.


23:58  

Next episode I'm going to make it do damage and knockback then I'm going to kill on a click and make the dummy knocked back and take damage. But this is it for now. I'm running out of time. I hope you learned something. See you next


LihatTutupKomentar