Transcript: How to script on Roblox - Roblox combat system HITBOX (episode 3)
0:00
Yo, welcome back to the car batteries. Today I'm going to be continuing the last episode, or now we're going to be making the hitbox for the for the damages. But But first we're gonna fix something, it's gonna make a promise, we're gonna fix some stuff. And yeah. The here's the problem like, see the district is inside the backpack right now, right? The script is inside the backpack. But if you remove the script, you click, it won't work, right? Okay, this is a little game, you don't want people without the script being able to punch in. And the problem is that exploiters can actually access the script. It's almost since there's no security, okay, let's do workface dot.com, add function, invoke server forgot to add an issue, it works. S. But we don't even have the script. That's why that's an issue to fix this issue, or gonna put this inside of your character scripts instead. So instead of being inside the backpack, it's inside your character model. And then instead of do instead of
1:32
a script apparent, then okay, now move this script this and not being appears to differ from theatre, oops, from director. If the player that part of the function isn't the character, then it's gonna return and Okay.
2:10
itself wait for child undo function, I'm going to explain this up because I want to do want to do the combat. Right. And then we're going to ask one function, making any threat because if you do wait right, to do something like wait, the script will be delayed before will be the script will be ordered before the funnel. So the the Invoke server will be on the driveway, it's gonna wait one second, before playing the animation and on that, that's why we spawn a function. Because we don't want to do a lot of lazy if you don't want to waste and, or if you do a lot of threats, in general, the script will be laggy.
3:04
So we don't want to do a lot of delays, right. So we're going to spawn the function, so we can just do something like this and do this without the code being yielded. Right this, let's see if this works. This doesn't then it's gonna be really awkward. And I'll have to fix the car again. Okay, it was Thank god. Okay. We put the script inside of the workspace and click invokes or where nothing happens, right? What the fuck what? Oh, I think I forgot to move it to the workspace. I forgot to go to the server.
4:03
Eight works. Good server. We'll get to workspace then to this roll up. What the hell? Okay. Something's wrong key something wrong. Let's pin the character first. Okay, but the character then if let's do some debugging. Let's see what's wrong the player can get paid from American character okay let's see something scrolling Oh go down really hard. Okay, move this here click the Invoke s socioemotional system have something okay oh yeah it's because I moved it too late okay, I know it's because the character variable didn't appear okay. The character variable was sushi master and then we did the character variable the same with this okay that's why
5:53
not that's why we move this to the workspace so the character variable the variable value will be one space instead of our character god okay, it's gonna work also we're gonna do something like this speeding things up just so because it looks cleaner instead of this combo to Google combo combo squadron spinning things up Okay, okay, okay, works works works gait works okay okay, it will temple nothing happens if the oops but if we move this to
7:10
the certain steps it will work I hope if it doesn't work now. I don't know. Okay, it was Thank god. Okay, now we're gonna spawn function. Okay, okay. Everything's done. Okay. Now we're going to talk about the hitbox I've tried using this rake asset box, but it's it's really late Okay, I'm gonna show an example right here it's a totally delayed because before
7:51
but this example space because we're gonna add comments real quick um, you don't have to do this but I'm doing this because it's good practice
8:06
and it's easier to reason greater that's more equals acquire code space versus bonds bond from shitbox trader Ray okay she, it's really weird this Imagine hitting your opponent like this. It's so unreliable. That's why we're not gonna gonna use this. It's really unreliable.
9:37
And it's inaccurate because of the it's not the modules for fault. It's because of the robots fault. The clients replication is because of Roblox. Does that. That's why
9:55
it's really late. That's why we're going to use revenues magnitude what can you expect me to I've made a video on magnitude
10:09
if you can watch it but there are a few issues with magnitude magnetic worse it can be messy have to loop through every prayer every clear ProClick if the text it could punch someone from behind okay let's put the issues right here
10:32
okay
10:36
well okay issues issues issues issues number one shooting someone from behind to the whole workspace for your character is inefficient free I've seen people have seen the YouTuber blur his scripting YouTuber. He didn't use magnitude because of this.
11:25
I understand. So I made the combat system I now instead of using magnitude now I'm now using hitboxes because hitboxes are way better than magnitude. So first I'm going to show you how to add a little stuff here. So once you first equipped it to use oh, by the way, you're gonna have to make all the enemies.
11:51
Yeah, he doesn't like using magnitude. Why? Because when you click the magnet types ones, and it doesn't follow your character. Click first ones you miss once and you're done. Okay? Miss ones so, the magnet virus only one time only virus one. Okay, this one, too. Okay, I'm gonna. Okay, so those solutions, solutions for this looping through the whole workspace is inefficient. Okay, we can do one we can do either looping through the whole players. But I don't think that'll be a good idea. Because NPCs are not players and pieces exist to Okay. So that's why I'm going to be making a global variable. So I'm going to be making a global variable that containing the script converts yam going back back in time, tricky middle to make a global variable for the players and NPCs now we're gonna loop through the variables so we don't have to look through every single part, every single model every single camera every single chain, so it's going to be efficient. Okay. Let's make the script right here. Your table alter table to make global variable. You don't do this, right? This is not a global suitable for making a global variable that's B that that can be accessed for from any scripts right? You need to do Alcor G, underscore G and then you'll need the name of your table wouldn't even care to table table you can be whatever you want. But I recommend you using all caps. So you know it's a global variable. Okay, now the tricky part is putting every single character inside of the symbol okay. For this we're going to do using NPRC let's add a comment through putting every existing NPCs. For AI character character in Paris he can put leave you for space can children know the cause? With something similar to do this in my magnitude video, you can watch. If oops, not, if you might if you might, then table insert, you need to put the table list the number position and the value, we don't need the number position. Key character table. Okay, we don't need, we don't need the normal position, we just need the value. Since we're not making a custom index, you can make custom index like this. This is a custom index is basically the same as making something is basically the same as this one, right? But it's a string instead of a number. It's pretty useful. I'm gonna stop rambling. Okay, then the value and the value which is the character then when the NPC dies oops, moving people when they die, space shelled, removed. Connect function show Okay, oops, I'm chillin in the secure
16:38
and easy way to do this we don't have to check the human items. I mean, it's pretty impossible since the character is removed from the workspace right how are you gonna check the unit we're just going to check if the character is inside the table. But this if character if they will find character oops people table and people find not explained this day. If your table and index the table dot find table dot find is used to return the index value okay, let's make an example in the fine let's do something like this local table is this is your mom, your mom and then you don't access you don't find the variable by using table your mom since you can only use this to to use the index right? can either do or you can't put your value inside of this you need to put your index like one or two okay, that's why we're gonna use table fight but people will find us is it returns the index value. index means number whether the number or the order value of the table and the value good we're going to use the global table and the character and now we're it's returning the value let's say I'm your character is in here right Kevin? Is Ma'am Ma'am Sir Okay ma'am sir. And then if you do this right, if we do the character is man's right? It's gonna it's going to return one because it's the first value inside of this table sheet one thing for them saying okay, seeing their move, you can't use for more value you can only use index that's why he was able to find
19:18
now we're gonna do a special child added shot. So when a character responds or joins they if it's a character then it will be inserted inside the table
19:48
okay, if you might people Wait, it's gonna I'm gonna make a loop function that will literally keep printing the
20:08
table okay excellent nevermind we shouldn't do this just function that way because it's a global function like f function it's a global table we can do this see let's do this one so we'll do this look around on to this I don't know why it didn't work on the comment
21:11
see dummy and social matter okay if we add an dummy add in dummy oops if we add an dummy sitting units down let me three and a normal is going if we add this again
21:47
there will be no dummy dummy and only social mastering Dmitri so that means the script was really good.
21:55
Okay, we're gonna move the okay all right. Problem one salt. Probably one salt. Now hitting someone from behind. Okay, okay. It's gonna make this problems is that okay? Since this is a bit complicated
22:23
All right. Now for the for the magnetic we're gonna make a more distant okay we're gonna make function module hit we're gonna rename this later normally instance instance the hitbox hitboxes and the range the deletion absolute
23:06
Fine Okay, so we're gonna we're gonna check every single every single we're going to check in the character table table and see if they are within the range by doing form maybe in just a character anime character he hears about a crucial key dot character table do not switch which fight
23:55
in Paris in fuse okay. Do okay and I'm gonna add a no for loop in pairs loop I parts part in Paris a car so it's going to get the children then if part is a bass part so basically if the child if the child here is a part if it's a body part if it's a limp then we're gonna make we're gonna do we're gonna make it take damage will take five damage
24:59
then take damage 100 Let's be crazy What's this 100 require the function of your attorney of this magnitude hitbox the box you happen to hit while game server storage modules box magnitude hit the hitbox character by arm arm of the character so it's gonna base the distance off of the right arm
25:53
then the range three feet that ration hydration right now at least okay
26:13
so the problem is I forgot to to make sure that I'm not am
26:28
if stop do this take your calculator if character if not careful character in if not a car if a car isn't character so if the model isn't character then it's gonna fire this this will hopefully fix up
27:17
when we get to five damage since I don't want to kill my damage instantly look to the one submit it's fine I guess we're sure we can return time well okay, so the problem is it only hits the magnitude only first once they do this the winch forgot to go oh yeah, that's true actually will make the magnitude. Okay, his heart is
27:57
hit
28:00
box box minus position dot magnet magnet is basically converting the vector string, which is three numbers into one number is smaller than the is smaller or equals to the range okay, let's be there, let's let's, I'm gonna explain this over re explain this. So when the function is fired, it's gonna check every single value inside of the character table. If the character isn't your character, so you don't damage yourself, then the human readable character, humanoid, this god there then we're going to do in Paris loop to make sure to check every single part if it's a part of them to check the position or the position of monitoring. So we're going to check every single part inside of the of the character and make sure that the position is smaller or equals the range. And yeah, this is basically we're doing this because to make the hitbox accurate, that's why we're checking every single part and instead of just checking the human report
30:09
the range is is I did something wrong is oil is supposed to be smaller than the range. That's why it's like that. It's simple smaller and equals to the range or not bigger, or equals okay
30:33
see, you can do this you can only do this yeah, you can't do this since the magnitude only fighters wants
30:51
Yeah, that's bad. Okay, so to fix this, we're going to do is we're going to use front service at this local RS equals game service run service okay, we're going to simplify this for us and we're gonna define connection first. Okay. And connection equals service. Heartbeat the duration will matter. duration will matter. So we're going to add a collision here. Let's make this point
31:57
okay. And couldn't be okay
32:18
Okay, so with this right. So run runs for beta heartbeat is basically you check every single frame every single frame. So it fires the magnitude of every single frame. Which means it'll be more accurate firing every single frame making sure that it's the magnitude is within range, then sick damage
32:52
this it's firing every single frame. See it instantly because it keeps firing was different. But the problem is that it keeps firing, it won't stop this why I added a connection. Okay, who can do something like this. Let's begin we're going to use now are going to require a module
33:20
local Red equals storage module modules module. Don't forget the requirement you can do this or you can do something like this local server storage
33:44
equals service. Service server storage, okay? into this. I prefer doing it this way, because if the server story isn't loaded, if it's nothing, then the script will be fucked. That's why I prefer using game get surface surface storage, but you can just do game on surface Retrophin doesn't matter since the module scope is in several stores either way, but I'm doing this because it is what it is you are doing this? Because I don't know. Just to practice, then we're gonna do for adding a delay label the declaration in the function. Okay, so it's gonna wait the duration. And then we're gonna do this connection disconnect. What this does is it disconnects the heartbeat. Okay, this can disconnect the heartbeat and the heartbeat so it won't keep firing the magnitude okay. So it's gonna wait for the duration and then it's going to disconnect the heartbeat along
35:17
35 minutes Yeah. Burst versus air. Custom threads is not about remember. Oh, yeah. I forgot to do dot modules.
35:31
As you can see it's been 35 minutes pretty sure the video will be like 40 minutes it's a pretty there's a lot getting covered in this video. So it's it's it's fine I guess.
35:51
Only 60 frames because it disconnects after the region obviously there's another pop the dog so there's another problem. The problem is that the hitbox starts instantly even what wanting up the books is starting that's why we answer the wait point 16 My oh it depends on your animation with my animation the wind up what last like 60 seconds? Well if your animation if you're gonna wind up last like two seconds then do wait to my animation last point 16 seconds. So I'm waiting on 16 So it's gonna keep waiting until you're not winning up when you're punching when your arm is striking it far as the hitbox but while you're winding up it won't follow that box since it's their sweet punch 16 Well depends on the animation then we're going to change the duration depends on your own how long your animation lasts yeah
37:21
what the hell what's wrong here? They come over Skype for some reason. I do not know why
37:39
let's see let's check the combo Yeah, keen to instantly
37:51
once upon so I guess this will So Oh, yeah. It's because it's because of the because of the threat module, right? Here, or this. The problem is, is that actually, I don't know, what's the problem? Play with it.
38:40
Okay. But instead of doing this, right instead of doing this just do
38:49
module? Sure, no. No much wrong with this. Okay, it Oh, yeah. She put that there was a delay. So it's because of the weight. Because of this few kilohertz make sure. Oh, it's, it's outside of the span function.
39:32
Spawn function is here. And is you the on server invoke? This is the delay this? And it's, it's off to be like, okay, so put your script to JavaScript inside of the we are inside of the spawn function? I am, I forgot to put it inside the time because of the example because of the threat. Modules for fault is because I forgot to put it inside of the spawn function. It did work now. Okay, see, lining up and fires it far. 16 Front, keeps checking every single keep checking on seven inch jack, jack 777 times I think 17 times do you check something times. And then it didn't check until I finished winding down. Because of the other weight right here. We said the weight went up, I'm going up. And then it fires the magnitude. Let's continue we're going to something like this. So that means the problem is fixed. We can move this. There's one okay. But there's another issue. Let's, let's replace this issue with hitting someone multiple times. Okay, so, to fix this issue is it's Pentacles Okay. Let's do something like this local kidness hit, stable, whatever we can see why. So, in theory, is we punch the punch, and then we check if the character is inside the hitlist or not. If they're not inside of the hitlist, then punch and then put it inside of the head. If they can do is instead of the hit list, then it will stop, then it will ignore the character. So, to do this, we're gonna do something like this. If a car is stopped your character and hit list find it list then we're gonna find it will check if the character is inside of the list and not. If it's not, then it's going to continue with the script. If it is done, we're going to switch to another character. And then we're going to do it we're going to put this inside of the table, insert, hit list and the value just I hope this works if it doesn't let's move on. I think I think this will work.
43:10
Okay
43:14
okay. This worked halfway and not not if it's not in serverless then it will continue to if it is then it will switch to another
43:35
this see oh yeah, it can only hit once because of it's still in the hitlist. That's why when, that way we're gonna remove the character from the hit list. So we're gonna do this by just doing this afternoon just just do this. They're fixed. So, when you were the operation, when the treatment is over, the connection will disconnect. It will stop firing the frames, and then they'd look the hitlist will reset Okay, let's see how long this video 44 minutes 44 minutes
44:32
check on it's probably 95 or 75 something form okay
45:00
okay, let's just let's just do this just do this. So it doesn't hit multiple times for now it still hits. Oh yeah, no, no, no, I don't want Oh yeah. It's because we didn't add a break. Break. So what this does is it stops this function that is in Perth. It stopped this impairs loop. So it will stop looping. So it will stop looping right you look through the parts and then check the position once it hits it'll break
45:41
stop this will work okay
45:57
yeah, it works let's add another duck let's see if it's able to hit multiple characters Okay. Check it out. This this is cool fish see it is multiple times so that means it works great. Okay one issue solved then hitting someone from behind Okay, so to fix this issue, Unity use something called dot product. Okay. Product is basically a function that checks your angle, that actual angle and compared to another angle and see if it's behind you or in front of you. There's a tutorial by by this guy should watch out if you want it's pretty good tutorial if you don't know how to you stock product. So what we're gonna do is we're going to add another model script for the dot product function. Actually, yeah, we don't need to just make a dot product function up here. But make it unable to be accessed by yours. Accessible function something like this function. This is an annex unaccessible function. This is an accessible The function so people will can't access it through this and do that you can't do get up see it's impossible so this is you need to get your we're gonna make a parameter two parameters and actually non
48:24
short part one okay oh chap Oh yeah. So for the product you need to use look vector and then dot
48:46
product right up to the right now
48:50
by using dot the dot function Dandan MVC look is okay okay local unit equals good part one or part two one good part one
49:15
unit so what this does is it ethical position yep position your position so it because it finds the position between both of these reports and then converting it to unit it's different from magnitude with magnitude it's just one number and the unit is basically just one zero and negative one and in between I guess it's going to be useful to look look look so it's basically the the front piece of yoga and then we're gonna get done unit then look so look at the look around so basically then we're gonna return this water turned us is basically a menu even the sub level print kept up usually you will you can't you can't do this right usually and do this but few use return unit then let's say the dog is like the dot value is 20 and if you use cat dot since there's fettering unit it'll return this value so if you put this there's gonna it's gonna be 20 If it's funny then it's funny that God is 11 minutes
51:08
this will be useful okay and get done actually name this guy named as to enemy unite, so there's no confusion
52:00
and enemy route our focus so the human eye is your characters, and the enemy human is the enemies just out
52:43
here, so in this video, let's skip this real quick. See if there's a reference. If the value is zero, that means it's in front of you. But if it's minus one, that means it's behind you. Let's continue Here's something like this, if it's smaller than point five than smaller than point five between zero than a champion often to get down in FLV, but we're gonna do if it's smaller than zero, let's check the fob real quick. This 0.5 If it's smaller than five
53:32
from each other, you'll get negative one. So hopefully this picture that I have up right here, from 60s is in field of view, but we can see is greater than point field of view which ranges from here, all the way to about here.
53:51
Yeah, amazing. Okay, so and get done. I hope this app you understand what I mean by what you understand our product. If you don't, then you can watch this guy's tutorial. It's really useful. got dark roots, then then we will founder and is small. So basically, if the character is in front of you, then it's gonna take it out.
54:44
It's dusted up. I hope it works. Ports but if you do this it doesn't take much. Okay. This is it for this tutorial, right? Every single issue is fixed. So the next episode we'll be using oop, so making something miss or making an object or something like we can add probably something like let's say the SIM card box. I don't need to hit box. A we are making properties and stuff the range making it customizable and making it like that and right now the hitbox only works for right arm and other parts such as the leg, left arm working on the key usable for every single part. Next video. Okay, does it for this video. How long has it been? It's been 55 minutes. Oh my God. God damn. Coughing suck too much. Yeah, see you next time. Bye.