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,
is a form of anti exploiting. So basically the client can't make changes to the, to the server.
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.
Or I'm gonna remove the script right now.
Sorry about that. Or do play right now.
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.
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.
But if we switch to the server,
the health doesn't replicate. Right. But what replicates is the animations. The animations is playing on the client right now.
Here's the proof. Goodness.
the animations are playing in the client right now. And it replicate to the server.
Anything but but that doesn't replicate the position of the character rapidly it's though, let's change the speed
It won't replicate. Let's see.
You and I
the speed, the speed will rapidly at its 16 fight here is a
100. But if we walk right here,
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.
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.
the local script in a star pack local script and make sure we get your animations ready. But
wait, let me I have made the animations before beforehand.
It's a free model animation.
Let's load real quick. I'm missing one animation. right
let me get the animation report. So what you need to do is basically get the ID
let me fix that issue real quick. 65 like you're
looks pretty fine. It's a pretty model animation.
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,
then you can either save it,
and then you need to copy the ID
or an animation here.
Thank you just paste it right here, you don't need anything else. I'm gonna rename this to punch five.
Right, now that you know how to set up your animations,
we're gonna make the script
gonna call this combat
First we're gonna call the local peer
game players, local player, which means your local player is basically your local player, and local character.
So it's gonna wait for your character to be added.
wait for child
character, because your character, your character name isn't going to be kept your name is going to be
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.
Right, it's going to wait for your character, it wait for shoulders and work since you have a unique character in
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
And then we're gonna do events.
I'm gonna explain this just follows. Then a user interface in good service user input service.
User Input service dot input began. So basically, when you're gonna when you when you click
your buttons, basically, if you click
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.
We're going to connect it to a function
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
the input parameter is first and then the process of typing.
Then, if you're, if you're typing, do then return and so you can he can punch while typing.
And it's input input right here, input dot user input type
dot user type, oops, type, but mouse down then, right okay.
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
key called input dot key code and m dot key code.
D, for example, but we're not doing that right now we're checking if the character is clicking.
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
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.
And then all you're gonna do print kit.
And then to make it off cooldown, then just wait
to 2.1 seconds debounce equals false.
So when you're reading your
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
mouse button one, one must mouse button one, or M one.
Whether they click or not, then it's going to fire this function.
It's not, it's not going to do anything, let's open the output
this works, this works done, we're just gonna need to make the combo local combo equals one.
If combo equals equals one, then
else, combo equals or three, then
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.
Okay, when you hit
your mouse, and the combo is one, you're gonna print one
change the combo to two. And then if you click again, with the combo, it's still then you're going to print
just keep doing this
and then after this, after your final hit,
you want to make the combo reset back to one,
you hit four or five times right, it's gonna print five, and then it's gonna reset back to one,
then I'm gonna wait for the doe like point, point four seconds and then
change the D bones to false. So you can M one again, you won't be able to spam it since school down exists.
12345 features back to one. Now that the base is done, we're going to make
a remote event by
let's what this right here, rename this to combat event.
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
use the server script way too much, it's gonna like lag like crazy server lag is really bad.
So we're just gonna
define the path to the event combat event
script we cobbled combat event.
When the combos one is a file server
so what we're doing is when you click Write, and then once you collect
the event will fire to the server, the server script I hear
and then it'll send the combo variable.
Okay, let's define the event. Script dot parent with a child combat.
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.
function. Right The first parameter is the player is the player and then that sent the event right.
The player the first parameter is
the player that started the event and then the second parameter is whatever you sent here. Okay.
We're gonna do player an undergrad
combo, since we think we send the combo, the combo variable,
okay, and this is going to be useful.
Right, we're gonna count the combo
and then we're going to do the same thing
show this screen, this screen because it's fired from the server script. If it's below then it's fired from the client.
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.
This is sweet, right? Wait three print. Hey
with three infantry
wait three, right.
it's gonna wait three seconds for Hello. And yeah. So if you want them Yeah.
If you don't want them to wait three seconds, for a year. Use delay, right, Les?
Three SEC point three seconds function.
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
Yeah, hello. See?
Because it's on a different thread.
Yeah, it's gonna print first. But if we do, wait, three and print Hello.
Yeah, it's neat. Boy, it's gonna take three seconds to print the and I don't want that.
You can do delay. Point, three, five seconds function.
I'm gonna event fire client.
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.
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
we're gonna do an event.
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.
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.
no, this should work
See it works and the debounce works okay.
Now you check your humanoid and you have an enemy right
It's used to play animations. Okay, first we're gonna and then first we're gonna make an animation table.
First wooden under wait for child animator. So basically
Roblox deprecated the humanoid load animation, because if the animator isn't loaded, it's gonna make a no no Mira and you
and it's then there's going to be two animators and your PC will explode. And
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.
Then we're going to make the animation tables. And
with the animations like this below here.
not anonymous. Punch one.
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.
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
punch one. But I have a speech right now.
Right, we're gonna just gonna load the animations.
We're gonna load every single animation,
and then we're gonna play the animation Adams.
play. So what this is doing is basically
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.
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
the animation and server script wants synchronize so that's bad
right we just do this
and the animation should work
see the animations worked this cannot reset back to the to the combo one animations.
Right this is the base for the script. I hope you learn something today.
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