How to make a Game on Roblox - Roblox combat system REMOTE FUNCTIONS (episode 2)

Transcript: Roblox how to make a combat system - Roblox combat system REMOTE FUNCTION (episode 2)

Well guys, welcome back to the Combat series today on we're gonna continue where we left off, we left off, we added animations, and we added a prince, and we had a system that prints out the combo. Well, unfortunately, it's just animation for now. But we're gonna add, we're gonna make it do damage, we're, first we're gonna fix some problems, there was a few problems here, there is a remote event problem, there's a debounce problem

there's a combo problem, there is a two way problem, but slot bought the first problem motor bands problem. So I read this article on the Developer website, it said that most events completely ignore lag. So basically, when you have 5000 Ping, the script will ignore lag and just run this run the other script immediately. Meaning the scripts the local script, and the server script will not be synchronized. So to fix that, see, it's not gonna be

it's not going to be synchronized. Um, so to fix that we're gonna use we're gonna use this remote functions, it's almost the same as what events but it waits until the server receives the message, and it runs to the next script, we're gonna add a remote function

add remote function and so basically it works it kind of works the same as what events but it waits until the server receives the message mode function then we're gonna completely remove this gonna fire the remote instead of fire server, it's invoke server Well, yeah, I forgot to disable this. Your, His arm was function. And I'm going to review it real quick when we do this

okay, so instead of events we're going to use for mode functions. It works almost the same as from old events. But instead of fight or server, it's invoke server and it it doesn't ignore lag when the server hasn't received the message it's going to keep waiting. So the server has run out good. And then the scripts will be synchronized

remote mode remote function invoke server okay. And instead of event occur remote for more than a remote function remote instead of on servers meant it's remote on envoke server

seen right here on server invoke I think instead of connecting commits function, we're gonna print the player

gonna move this over the event Yep, it prints out the clear. And now, the next issue, which is combos, so the combos doesn't reset, and we make them reset, it's can, it can be highly exploitable

because the combo is client sided right? Is Converse coincided, exploiters can just change the combo back to one. And then you can also exploit this if you have a weapon, like if you have a sword, and the combo is coincided, you can just do four clicks, and then wait until the and then switch back to this and then switch to sort the default clicks if we add, if you make the commerce reset. So we can fix this by adding attributes. Global global combos attributes are basically custom properties as you write here, this is the dummy This is the properties that we can add an attribute, but add a attribute like we're gonna name it Congo, and then we're gonna change the type to number schema, save this, then it's going to be like this. And then the combos will be global client can change it that can be exploited. Only the server script can change it then we're gonna set the attribute. So to make an attribute, we have to do set attribute given the players player added connect function Player, Player the player character added on act function character, so Sony Play responds in, it'll activate this event, then we're gonna add an attribute character set attribute combo and then the value this is the name and this is the value.

So, when we load in we can have an attribute as seen here, not really, and then if we reset

the attribute will also respond with your turbans. See, then okay, this is the next issue is D bounces, instead of the bounces, we're going to use done global the bounces. character set attribute stand equals false. So we're gonna make it so when you're not when your standard, you're not able to click, you're not able to punch. And it's not exploitable, right. If you change the value on the client side, it won't replicate. And since it won't replicate, the script will not run, even though the animation not here. If it's exploited. We're gonna add a we're gonna add a check if the player is done or not in the server, since we can trust the client, we're going to check on the client and the server. Okay. We're going to remove this and do some changes. If character get attribute that's how you get an attribute. That's then combo. Oops, done. So it's how you get an attribute and we're going to check this done if it's false or not, and that will make it tell the true they're not true. And so the script more done than everyone if the Explorer moves this we can Just do something like this

figure character out of character, and then if character get attribute stand, let's evals true, they are true. And even if the expert was the script, even if it is SQL script,

the server will prevent it for from punching. Then we're gonna play the animation like your animals. Animals, character, get attribute. Combo play, so it's gonna play this animations depending on your combo. So if your combo is still, it's gonna play this animation right here. It depends on the order. And then we're gonna, we're gonna change the script trickier

don't change the combo in the server, we're gonna make a combo variable real quick. Local combo plus character. Combo, we're gonna do the same for Stan you can just change this to stand. Okay. If combo equals equals one, then combo character, my fucking god character for as we can, we'll cover plus one. So set attribute set attribute is used to create, create attributes or modify attributes. In this case, we are going to modify the attributes.

And then I'm just going to keep doing this fumble you know, we're just going to do the fast way, and we've come across five, changes to one. If it's not five, we're gonna we're gonna change this to plus one. So when your combo isn't five companies 1234 It's gonna, it's gonna, it's gonna, plus this crowd, it's gonna plus the combo, it's gonna make the combo higher to the next number. So yeah, it's five, that's gonna reset back to one. But as you can see, there's going to be an issue. We're gonna play this real quick pleased the second animation y, z, it plays a second animation first. Why? Because the script, because it changes the combo. Before the local before the client plays the animation. I can prove drag Euro, we're gonna do wait five, then it's gonna wait five before the client, please the animation. It's because it's not when the script receives the event it, it runs. It's when the script completes the entire script, when the script runs the entire script, and then it will stop the wait function will stop yielding. And then please the animation as you can see here. I click it's going to wait five seconds until I start kicking or punching. See, it's going to wait until the script runs the entire thing. And then and then the client case. So we can do this. We can prevent this by using spawn function. So it's going to be on a different thread. There's also going to be a problem right here.

See, there's the problem, the problem that it changes instantaneously. But even if he put a weight, it's gonna work if you put, if you put a weak point one, it's gonna wait until the animation plays, and then it changes the combo. It's going to work, but there's going to be a slight issue

the issue is that spawn doesn't spawn a function instantaneously. It's, you know, wait a few seconds, and then it's going to spawn, people have been saying in their forums that you should avoid spawned. And the less that's this is why this is an issue where we'll get to the lease. This is the only issue if you spawn delay, game with the breeze, play game, the breeze riding. So given the breeze, a rubbles an item within a few seconds, this is the object, this is the time or the duration. So the problem is that it doesn't fire the function immediately doesn't function immediately. That's why you should use Courtine Cortines are like spawn functions, but you spawn them immediately coroutine wrap function let's call it the if this quarantine function. But the thing is, you still need to call the function if only to call the accordin function, you need to call the function like this. But we can, we can avoid that by doing like calling it immediately like this, then it's gonna be instantaneous. We're gonna make a mod module script, or module script that handles threading, like delays and spawn function. So it's going to make our lives easier. Since the built in delay, and built in spawn function, are pretty bad. That's why we're gonna make our own custom from thread script. It's not gonna be it's not going to be hard, it's it's pretty simple script. First I'm gonna explain models come to you if you don't know what it means. Model script is basically a script that can be required. And you can it's basically a global functions we can call the function, so you don't need to write the same thing over and over again, it's gonna make your life easier. If you make a function, you know, like local file local function, the here you can call it, this uncover function. If you write the function like this function, module, D, module dot d, you can call the function you call the function by first requiring the module script call module wire, we will start module script, then module dot d, you can fire the function, we're gonna make it print modules are great as you can see, modules are great. You don't have to write the same thing over and over again. It's pretty it saves your life. We're gonna rename this to custom threads, custom threads. This, you don't need to rename this the custom threads, okay? It doesn't matter that this model name, this doesn't matter. The name of the model group doesn't matter. So you can just name it whatever you want module threads, and then we're gonna make the function. We're gonna make our own spawn function on so usually you need to do spawn function function like we're gonna make our own spawn function that we're gonna make. Instead well with the spawn function, it's not spawn function, it's module that spawn function. So let's make the customer spawn function function module, that's fine. And then add a parameter funked or function, rename this function. So because you can't use function as a name, or as a variable or a parameter, you need to do because it's a snap supposed to be made for variables, you can make it you can make the F

high case or you can just do F for the player it doesn't matter really, then 14 dot wrap

function we're gonna call it right here, then we're gonna call this function here. So we can just do something we can do something or something like this

module spawn function function print. Yeah, it's gonna work my gosh, oh yeah, I forgot to rename this to the custom plants

see it works. It we're using this instead of the default spawn function because the spawn function doesn't fire the fire of the function immediately. But if you use coroutines, it's gonna find immediately now we're gonna make our own custom delay function, les module module, Joe delay time. We're gonna be this Tim and the function number Courtine wrap function with Tim and then fire the function also put in a wrap. Then we're also going to make our own debris function The object the time contain wrap function. We're gonna call this by doing this wait T and then object destroyed Okay, and then this will work we can just do we'll name this the thread

thread dot delay one files function we go this should work fine All right, we're also gonna I'm gonna stand the player witness down the player because if you don't stop the player when you mash click,

this will happen sort of it. If you might click and you don't stand the player, this will happen. Okay, and now we're gonna understand the player character set attribute stand true, and then add a delay thread delay on point 25 function. So we're gonna change back the stamp to false

this changes on our thread. This changes the economy One different trend and instead of us being easy, you can just do this the hard way because we're in this long way because we need to reset the combo. If combo equals equals one then character too it's gonna take a while but it's, it's gonna be worth it else F equals equals to change its tree

for Google signals five for that five those five changes to two then we're gonna add a delay thread delay from point A to point one second or wanting to refine actually instead of doing can just do it yeah, we can just do wheat wheat one weekend 1.5 If combo it was it was one acre tsutsu then combo equals one where it's going to wait point five seconds so really don't when you don't click 4.5 seconds the comparable shot that's one that's changes let's change this to one so it's not way too short

then we're gonna do the same thing this this this if combo actually now five four then three I hope this works they should work in theory and then 1234 Wait for better than one oops one two wait for one second then row

doesn't work Goddamn it doesn't work so stretching this point one let's see if it really doesn't work print able to do some debugging

well this works yeah we'll reset back to one Why don't fumble golf it was Susan B is not C see. Oh yeah, I know why my bad I didn't change the combo to this.

I didn't do this I forgot that this attributes are not some variable. Okay, they should work in theory they should work and we forbid and then it should be set back. Like go please. Wasn't there this working bro. Print as this should work. I don't know why it's not working.

Let's check our camo real quick. One, two Didn't work oh I think I know why yeah I know I know why actually never mind oh let's try something let's let's try character attribute combo instead of combo it was it was a try