[Part1] Easy Roblox Combat System for Beginners | (Basic Roblox Services, Hitbox Detection) — Transcript
Full transcript
- 0:00All right. So, um the first video I just
- 0:03didn't press record, so this is going to
- 0:06be a second time. Uh this video should
- 0:09be around 40 minutes. And this is going
- 0:10to show you like the basics of how to
- 0:12make a combat system. And that's pretty
- 0:16much it. I'm also going to show you how
- 0:17Roblox um works in general, how Roblox
- 0:20Studio works, and how um it's sort of an
- 0:23objectoriented type of um compiler type
- 0:25of system. So, yeah.
- 0:30So, first things first, let's look at
- 0:32the starter character.
- 0:35So, if we play the game, we'll notice
- 0:37that workspace, which is the whole thing
- 0:39over here, has an object called me. This
- 0:43is your
- 0:44character. If you open your character,
- 0:47this these are all the children of that
- 0:49character. Vice versa, the children,
- 0:52this is the parent of the child. So
- 0:55human repart is a child of my character.
- 0:59So
- 1:01another thing we want to note is starter
- 1:04character scripts. Anything and I mean
- 1:06anything that you put in here is going
- 1:09to be replicated to your character. So
- 1:12let's make a folder called core. Right?
- 1:14This is going to be for organization
- 1:15type of
- 1:16preferences. So if you play the game,
- 1:18you'll notice that your character
- 1:20automatically has a folder called core.
- 1:24So, you might be thinking, okay, there's
- 1:26something called starter player scripts
- 1:28here, too.
- 1:30So, yes, it does the same exact thing.
- 1:32If we add a folder here called starter
- 1:36player
- 1:37scripts, or I'm not going to name it
- 1:39that. Uh, something something like that.
- 1:42Play the game. If you look at your
- 1:44player, you open player scripts, you'll
- 1:47see a folder in there called whatever
- 1:50brain rod that is. So,
- 1:53Let's get started with the actual
- 1:55scripting portion. We'll call this uh
- 1:59inputs. You can call this whatever you
- 2:00want.
- 2:03So, let's uh first thing I want to note
- 2:06for y'all is comments. Two dashes equals
- 2:09a comment. So, you can write whatever
- 2:11you want here, but you can't do it once
- 2:13you enter a new line. In order to do
- 2:15that, we want two dashes and the little
- 2:18um letter beside the P. So we want to do
- 2:22that twice. One, two. And then you can
- 2:24press enter. Anything within this little
- 2:27white space here, you can type. So you
- 2:28test test test. Doesn't matter. It's
- 2:31useful for commenting for other people
- 2:33and yourself to know just how the script
- 2:36works in general. What what function
- 2:38does what. So let's call this uh core
- 2:41input client.
- 2:43Now, the first thing I want to emphasize
- 2:47for y'all is the the supreme usefulness
- 2:49of uh
- 2:52documentation. So, you'll notice that
- 2:54for pretty much every combat system
- 2:59uh well, a good one, you can hold your
- 3:02left mouse button to go a punch.
- 3:05So, to do that, we'll use something
- 3:07called run service
- 3:09right here.
- 3:11So,
- 3:13One thing I want youall to note too is
- 3:15the difference between events and
- 3:17properties or events and methods. So
- 3:21events will always have a period
- 3:24following their calling and methods will
- 3:27always have the two double dots. So
- 3:31let's define your variable called run
- 3:33service
- 3:35and let's look at the events called
- 3:39render stepped.
- 3:42So you'll see that it gives you a little
- 3:44description of it. Fires every frame
- 3:46prior to the frame being rendered. So
- 3:49this is good because now we can actually
- 3:51detect um continuously if the player is
- 3:55holding your left mouse button. So we
- 3:57can say run service dot which is an
- 4:00event render stepped after every event.
- 4:04It's going to be a muscle memory once
- 4:05you do it for like a while. But you
- 4:06always have a connect function open
- 4:09parenthesis and whatever like the
- 4:11arguments that the default Roblox
- 4:13function has for you which in this case
- 4:16we call delta
- 4:17time. It does not need to be called
- 4:19this. You can call it dt ab some brain
- 4:24rot but in this case we just do delta
- 4:26time. Another thing we can note is
- 4:29annotations. So this tells Roblox that
- 4:33this type of argument is a number. You
- 4:36can call this is a string is um a
- 4:40boolean but in this case it's going to
- 4:42be a number.
- 4:44So now we want to also look at a service
- 4:47called user input
- 4:50service. Every single game ever uses
- 4:53input service. So if we look at a method
- 4:58and we score down called is mouse button
- 5:01pressed. It conveniently has a way for
- 5:04you to check if your mouse button is
- 5:05pressed and it returns
- 5:07whatever doesn't matter. The
- 5:09documentation has it all for you. So we
- 5:13can say we have to define the service
- 5:15first like
- 5:18so and then we can say if user service
- 5:22is mouse button pressed a method once
- 5:24again. So these double
- 5:26dots enum user input type button one.
- 5:30Even if you don't know what enums are,
- 5:32user input types are the documentation
- 5:36tells you. It tells you exactly what
- 5:37enums are, default values, etc., etc. So
- 5:42we can say this and we can say print.
- 5:45Obviously you should know what prints
- 5:46are. So prints
- 5:49um clients left click.
- 5:52So,
- 5:54we play the game and if we left click or
- 5:58hold down left click, we can see that it
- 6:01prints it up. And if I let go, it stops
- 6:04printing all all from what? Four
- 6:08lines. So, I don't know why games don't
- 6:11know how to do it. It's dead ass. Just
- 6:13four lines, bro. See, it's still
- 6:15recording. Yep.
- 6:17So the next thing we want is
- 6:21um to notes uh replicated storage and
- 6:25all of these folders I have in here.
- 6:27Once again organization um purposes
- 6:30preferences doesn't really matter but we
- 6:34will reference remotes like so. And in
- 6:38doing so I'm going to show yall what the
- 6:39difference is between wait for child and
- 6:42find for child.
- 6:44The main difference is wait for child
- 6:47yields the script
- 6:49and find first child immediately
- 6:52attempts to um attempts to find the
- 6:55argument passed which is a string.
- 6:59So what yielding does right
- 7:03and why it's so crucial is if you do
- 7:05workspace wait for child blah blah
- 7:08blah everything beneath this will not
- 7:11run.
- 7:12So works whiffer child is used in the
- 7:17assumption that the child that you're
- 7:19trying to find is going to be added some
- 7:21time or another.
- 7:23But the default cutout time is around 5
- 7:26seconds. I think three or four or five
- 7:28seconds. So if I do play you and I hold
- 7:32left click, you'll see that it doesn't
- 7:33work
- 7:35and an infinite yield should pop up.
- 7:37There you go. So you see infinite yield
- 7:40possible because it just wasn't there.
- 7:44So yeah.
- 7:48Now and knowing that we will do local
- 7:52replicated
- 7:53storage game get service cuz we want a
- 7:56way for the client to communicate with
- 7:58the server saying that okay I want to um
- 8:03attack.
- 8:05So we'll say local remotes equals
- 8:07replicate storage wait for child
- 8:09remotes. The reason we do this is
- 8:12because the client doesn't load all
- 8:15these right away. For every new client
- 8:18that's added, it needs to load every
- 8:19single thing replicated storage. So if
- 8:21you do dot remotes, it will it will
- 8:25error occasionally depending on your
- 8:26ping. So to be safe, we'll wait for
- 8:28child
- 8:29remotes. So now we'll make a new remote
- 8:33event
- 8:35called attack.
- 8:37So, I don't know if you gotten far in
- 8:39the YouTube videos yet, but what remote
- 8:42events do is they let you communicate
- 8:43from the client to the server.
- 8:47So, we'll say remotes attack fire server
- 8:51like so. And once again, if you don't
- 8:55know what remote events are,
- 8:56conveniently, we have something called
- 8:58remote
- 9:00event. So, you have methods, which once
- 9:03again double dots. events once again are
- 9:06single
- 9:07dots. Let me get some
- 9:12more.
- 9:14Now we're going to make a script in the
- 9:17systems once again. Organization
- 9:19preferences. We'll call this comt
- 9:22system.
- 9:24Now comments just for me. And then we'll
- 9:28say local replicated storage because we
- 9:32want to get we want to reference the
- 9:34remote uh remotes folder. So we'll get
- 9:38service and then we'll say local remotes
- 9:41equals storage
- 9:44remotes. So the reason we do that is be
- 9:47it's just it's just for pure looks man
- 9:50pure organization cuz this looks ugly
- 9:52compared
- 9:53to this.
- 9:56So once again the reason well not once
- 9:59again but the reason we can do dot
- 10:01remotes instead of wait for child or
- 10:03find for child
- 10:05is because of the server. The server
- 10:09instantly loads everything in the game.
- 10:12So it instantly loads all of this
- 10:15uh all of this this everything. So
- 10:19because of that we can do remotes
- 10:20without airing.
- 10:22Now remotes attack onserver event which
- 10:27is a method and they even have open
- 10:29documentation for you but onserver event
- 10:34fires a script when fire server is
- 10:36called on the same remote event from a
- 10:39local script. I can't lie they did not
- 10:42have it before but that's really good.
- 10:44And it tells you what the parameters it
- 10:46is.
- 10:48So this these are automatically going to
- 10:50be present once you define the events or
- 10:53initiate it. So to answer event connect
- 10:58function remember muscle memory always
- 11:00connect function open
- 11:02parenthesis and you see that we have
- 11:05your little arguments in here. So
- 11:07player player because we want to be
- 11:10known as a player so we can access the
- 11:13um the the properties for it.
- 11:17Uh so yeah let's say
- 11:21this all right uh let's just add this
- 11:25back in another thing you see that we
- 11:28have something called tupole
- 11:30right anything after your initiation of
- 11:33the player you can add anything you want
- 11:36you can add test uh test arc test arc 2
- 11:40however this is frowned upon and most um
- 11:43old games do this for some reason but
- 11:46the meta is you want to have a table in
- 11:48here called argument data. This is
- 11:51anything after the player. So if we do
- 11:55that we can fire server.
- 11:58So a common mistake people make is that
- 12:00they say okay if the player is in here
- 12:02that means we have to do the player in
- 12:05here right? No the player is only a
- 12:09server thing right? It tells the server
- 12:10that which um client fires
- 12:13this. So we don't need to add player in
- 12:16here.
- 12:17But what we can add is add everything
- 12:19after the player which is argument data.
- 12:22So we can for example could be like
- 12:24holding space equals true, test one
- 12:26equals true, test two equals
- 12:29true.
- 12:31So but in this case we'll just make it
- 12:33an empty table for
- 12:35now. And there we go.
- 12:39So,
- 12:41we're going to check for the
- 12:43character local character equals player.
- 12:46character.
- 12:48The reason we do this is okay, what if
- 12:51the character is not there? That's going
- 12:52to be a problem. So, we're checking if
- 12:54there's a character. So, if character
- 12:58then then we can check for the humanoid,
- 13:02right? Cuz humanoid is always going to
- 13:05be there if a player is there. So, we
- 13:07want to make sure that the human is
- 13:08actually there and like someone didn't
- 13:09mess with it and destroy it or anything.
- 13:12Character find for child humanoid. All
- 13:14right.
- 13:17So, you'll see that um let's see, let's
- 13:19go over
- 13:21here. Humanoid.
- 13:25All right. You see all of these
- 13:26properties and etc for the humanoid,
- 13:28right?
- 13:30Typically, Roblox autofills it for you.
- 13:32But you see that it doesn't have all the
- 13:34functions for it like uh camera offset
- 13:37and stuff. So the way you can do that is
- 13:39through
- 13:40annotating. So we can two dots and you
- 13:43see that it automatically auto fills it
- 13:45for you. You can say
- 13:47humanoid. Now give the model. Yep. So
- 13:50humanoid like that. And now we can say
- 13:52humanoid at camera offset or anything we
- 13:54want. That's a property of the normal
- 13:56humanoid. But now once we do that we can
- 13:59say print
- 14:01player.name dot dot attack. So one thing
- 14:05I want to go through y'all with y'all is
- 14:08how concatenating works and how
- 14:10combining strings works especially in
- 14:12print
- 14:14statements. So in a print
- 14:16statement you can do print whatever you
- 14:19want. Add a comma tech test one test
- 14:23two. For every comma that's added, that
- 14:27means another space. So that's like
- 14:29saying
- 14:31attack space test one, space test two,
- 14:35right? So if we play the game and we
- 14:38hold, you'll see that. Okay, it's a
- 14:41comma after every single thing. So
- 14:44that's how one way of printing works
- 14:45through
- 14:46commas. Another way is through dot dot
- 14:49two dots.
- 14:51So you have to do make a new
- 14:54string. So dot dot doesn't automatically
- 14:57add a space between your um strings. So
- 15:00you have to add a space and then attack.
- 15:03Typically for me I like to do this just
- 15:05because I'm used to it. But comma is
- 15:08definitely more preferred throughout a
- 15:09lot of people. So up here we can say if
- 15:13humanoid then so we found the humanoid
- 15:16then we can say player name attack.
- 15:21So there we go.
- 15:23Attack. One major issue that you could
- 15:26see is it's spamming the server with
- 15:29attacks or attack prints and we don't
- 15:32want that. So one thing we can do is add
- 15:35a debounce or a
- 15:37buffer.
- 15:39So we can we can do that by saying if
- 15:43character find for child attacking. So,
- 15:47if the character finds um an instance
- 15:49called attacking, then we want to stop
- 15:51it from
- 15:52printing. Now, you may be wondering,
- 15:54okay, attacking, you're going to have to
- 15:56add something called attacking in the
- 15:58player for this to
- 15:59work. So, let's make a new instance
- 16:02called attacking equals instance new
- 16:06folder. You can this can be anything you
- 16:09want. This can be a bull value, an int
- 16:11value, a number value. It just it
- 16:13doesn't matter. In this case, I'm just
- 16:14going to do folder for just my
- 16:17preference. And now we can say uh let's
- 16:21go search instance new.
- 16:26Uh let's do instance. Here we
- 16:29go. There we go.
- 16:34Methods. Scroll through here. Scroll
- 16:36down a little bit. Here we
- 16:39go. Right here. Object replication.
- 16:43This is how you make new
- 16:45instances. So you see instance new part
- 16:48you parent it etc etc.
- 16:51So let's go back to
- 16:53here
- 16:55attacking.name. So we know that a
- 16:57property of a folder which you can find
- 16:59in the
- 17:01documentation. A property inherited from
- 17:04instance. So we go back to instance.
- 17:07Wait for it to load. You see that
- 17:09property of whatever is named.
- 17:13So we can call the folder attacking and
- 17:16we can parent the folder to the
- 17:17character which is what the script is
- 17:19looking for. Right?
- 17:21So the main thing people um need to wrap
- 17:25their head around is the difference
- 17:27between variable names and the actual
- 17:31name of the instance that they're
- 17:32creating. Right? So we can call this a
- 17:34as the uh brain route right here. This
- 17:38doesn't affect the name of this. Vice
- 17:40versa, if we call this blah blah blah,
- 17:44this script wouldn't work anymore
- 17:46because we're trying to find the
- 17:47instance called attacking, not blah blah
- 17:49blah. So, let's change back to
- 17:52attacking. And then let's play the game.
- 17:56You'll see you'll see one major issue
- 17:58with this. It doesn't work anymore after
- 18:00you attack once. See, the reason for
- 18:03this is we didn't destroy the attacking
- 18:05folder.
- 18:07So let's take a look at another service
- 18:09called debris service.
- 18:12Okay.
- 18:13Reload the page so it loads faster.
- 18:16So now we can go to methods. Once again
- 18:19remember methods have double dots,
- 18:21events have single dots.
- 18:23So we go to method add item. Once again
- 18:26basically what Adam does is that it
- 18:28destroys an instance after a certain
- 18:30amount of time and it tells you what the
- 18:32parameters are which is convenient too.
- 18:35So
- 18:38we can say
- 18:40well first off we have to make the
- 18:41service. So local debris equals game get
- 18:44service
- 18:46debris. Now we can say debris add item
- 18:51attacking which is your item instance
- 18:55comma let's say.5 seconds.
- 18:58Okay. Now this is going to add a buffer
- 19:01or cool down to how many times you can
- 19:03attack. So every.5 seconds you can
- 19:06attack again is what this is saying.
- 19:10Excuse me.
- 19:12Now if you hold left mouse button, you
- 19:14can see that it has a little buffer and
- 19:16it waits a little bit before you tech.
- 19:21Now that's good and all, but now let's
- 19:23go ahead and start with hitbox.
- 19:27Oh, also another thing, scoping a huge
- 19:30thing that you have to wrap your head
- 19:32around. How Roblox reads is from top to
- 19:37bottom. So one, two, three, four, five,
- 19:40six, seven, eight, nine, 10, all the way
- 19:42like that. It reads in a sequential
- 19:44order. So with that in mind, if we were
- 19:46to delete the debris add item, right,
- 19:48and put it up
- 19:50here, this would not work because the
- 19:54attacking instance hasn't been created
- 19:56yet according to the script. Even though
- 19:58if you look at it from face value,
- 19:59you'll see that it has been created, but
- 20:02Roblox reads from top to
- 20:05bottom. So you need to put this below
- 20:08the part where you instance the
- 20:10attacking
- 20:11folder like so.
- 20:14Now hit boxes.
- 20:19Let's go ahead and make a hitbox. And
- 20:21let me show you how the Robux
- 20:25uh part thing works.
- 20:28Let me add a new character.
- 20:32Like so. All right. This is our
- 20:33character that we can base the box from.
- 20:36Insert a part. Let me position the part
- 20:39to where the character
- 20:41is. There we go.
- 20:45Now, one major thing that you have to
- 20:47know is if you hold control and you
- 20:50expand or move your mouse back and
- 20:52forth, it expands on both axes.
- 20:56So let's say we want to go up a little
- 20:58bit. We want to go forward. I'm not
- 21:01holding control now. So if I hold this
- 21:03out, it's just going to move it like
- 21:04this. Rather, if I hold control now, I
- 21:07push this out, it's going to go both
- 21:09ways. But I want to move this out a
- 21:12little bit. I want it to be directly in
- 21:14front of the character. And I want it to
- 21:18expand out like
- 21:19so. Make it up like this. And we can
- 21:22call this the hitbox templates.
- 21:26Okay. Now
- 21:31an import an important thing you have to
- 21:33know for everything right is how these
- 21:35properties work. Can collide anchored
- 21:37and
- 21:38massless. If can collide is set to true
- 21:42then you can collide with it. If it's
- 21:43not then you can't. But in this case hit
- 21:45boxes we don't want it to collide with
- 21:47the character as in we don't want them
- 21:49to physically touch it and be bounced or
- 21:51a pulse back.
- 21:53So, we also want massless to be true.
- 21:56What massless does if it's false is that
- 21:58it adds sort of like a weight to the
- 22:00character. Basically, physics, right?
- 22:02Cuz you see over here you have a mass of
- 22:0554.62, whatever Robux units are. But if
- 22:09mass is set to false, then it's going to
- 22:12the part is going to add an extra type
- 22:14of mass to the character. We don't want
- 22:16that. We want the hitbox purely to be to
- 22:18be there just for hitbox detection.
- 22:21So, we turn these off. And up here,
- 22:24self-explanatory. You can change this to
- 22:2675. Transparency. Everyone in their mom
- 22:29should know what that means. And brick
- 22:31color.
- 22:33So, this is our little hit box. Like so.
- 22:36And we can drag this to replicate
- 22:39storage. Oops. There we go.
- 22:43So if I didn't mention this before, what
- 22:45replicated storage is and why it's so
- 22:47important is that everything that you
- 22:50want the both the server and client to
- 22:52see you put in replicated storage cuz
- 22:56the client can access anything
- 22:57replicated storage as seen here and same
- 23:00with the um server. So with that in
- 23:03mind, let's make a new variable called
- 23:06replicate storage assets.
- 23:09And now we can actually get the hitbox
- 23:10template from that.
- 23:14So we say local hitbox clone equals
- 23:20assets hitbox templates
- 23:23clone. So once again, if you don't know
- 23:26what clone does, we can go to the
- 23:28instance class like so. And now we can
- 23:32scroll down until we see clone, which
- 23:35should be right here.
- 23:37It tells you exactly what clone does.
- 23:40And now let's go back. We Let's call the
- 23:43hitbox clone. Let's name it, right?
- 23:45Hitbox.
- 23:46Hit box. Cuz we don't want to just call
- 23:48it template. That's kind of
- 23:50weird. And once again, name. That's how
- 23:53you know that's a valid
- 23:55property. Now, we can parent it to the
- 23:59workspace. There's already four in here
- 24:01from before, but let's print it to
- 24:03workspace boxes.
- 24:07Now, let me if y'all haven't seen
- 24:09welding in like the YouTube tutorials
- 24:11yet, I'm going to give you like a sort
- 24:13of brief run through what that is,
- 24:15right? So, local weld equals instance
- 24:19new weld. Now, we can say weld.part O.
- 24:24So, which is the first base part that
- 24:26the joint connects to. So, we want to
- 24:28weld the character's humanoid root
- 24:32part, right? So the character humanity
- 24:34part is this the thing that the player
- 24:37this updates every time the player
- 24:38moves. It essentially glues all of these
- 24:41parts
- 24:42together.
- 24:44Right.
- 24:47So let's get rid of that. We want to
- 24:50weld the character human part to the
- 24:54hitbox
- 24:55clone. Also we want to parent the weld.
- 24:58Always remember to parent cuz if you
- 25:00don't that it's not going to work. So
- 25:02there we go. And that should
- 25:05work. So let's do this. Oh shoot. Also,
- 25:10I forgot to destroy the hitbox. So we'll
- 25:14say debris add item hitbox clone come.5
- 25:17or no.35. We want a little sort of delay
- 25:21in
- 25:22between. So if we attack, you'll see
- 25:27that the hit box is in there.
- 25:32Yep. However, you see that it's not
- 25:34offseted
- 25:35correctly. That brings me to my second
- 25:37point, which is how to offset in Roblox.
- 25:40So, if we click on the human report,
- 25:42click on move, you can see sort of the
- 25:45axes of how the character
- 25:48moves. So, general rule of thumb is
- 25:50X-axis moves left to right, Y up and
- 25:53down, and Z forward and back.
- 25:57So, we can say well.co co let's see go
- 26:02down here the offset point so equals cf
- 26:06frame new 0 comma 0 because you see XY
- 26:10however we want the Z to be sort of in
- 26:12for in the front a little bit so I'm
- 26:14going to
- 26:16say3 play the game you see that the
- 26:20player the hit box is in front of the
- 26:21player a little bit like so
- 26:26so another thing we want to mention
- 26:30What I'm going to show you is what
- 26:32happens if King Cloud is on.
- 26:35Let me turn this off real quick and hit
- 26:37and go to the dummy.
- 26:40You'll see that there's no collision
- 26:42happening. However, if I go over here,
- 26:45turn this on
- 26:47and start walking up to the
- 26:49dummy. Yep, we do not want that. This is
- 26:52stupid and shouldn't be a thing. So,
- 26:56yeah, turn this off.
- 26:59Now the actual hitbox detecting
- 27:03uh let's go to uh let me see if I'm
- 27:06still recording. Yep.
- 27:09So we want to create a new
- 27:13thread, right?
- 27:15Threading. So let me go a brief overview
- 27:18of what task is and what threads
- 27:21are. Excuse me.
- 27:24So what thirding is is that it creates a
- 27:27sort of new parallel where different
- 27:29functions different scripts can run at
- 27:31simultaneously at the same time. So
- 27:34let's say this right we have two threads
- 27:37that means this runs in in a different
- 27:40parallel as this one. So if we were to
- 27:42say workspace wait for child which I
- 27:45mentioned before if we do this and it's
- 27:47not there it's going to yield right? So
- 27:49blah blah blah. But if from here we
- 27:50print this ignores the wait for
- 27:55child this is going to print anyways
- 27:57even though it should wait for this but
- 28:00because it's in a different thread or
- 28:02parallel it doesn't. So if we attack
- 28:07you'll see that this ignores wait for
- 28:08child. However wait you'll see that
- 28:11there is a infinite yield or infinite
- 28:14yield. This is because even though
- 28:18you've already made a new uh thread,
- 28:20errors can occur within that
- 28:23thread. This is important for
- 28:24understanding how memory leaks work and
- 28:26things like that because people usually
- 28:27just spam test at spawn if they like
- 28:31want things to run the same thing at
- 28:32once, but they don't disconnect
- 28:35functions. So, always always remember to
- 28:38disconnect your things and things like
- 28:39that. But knowing that, let's do the
- 28:43hitbox
- 28:44detection. So while true or while hitbox
- 28:49clone.parent do so what this is saying
- 28:53is while the hitbox is parented to
- 28:55workspace hitboxes we do. So testweight
- 29:01um another thing testweight you can read
- 29:03it uh don't use weight because uh it's
- 29:08separated. So
- 29:11we can do test.wait. So while the hitbox
- 29:13is actually there, we can do the
- 29:15detection.
- 29:19So let's go ahead and
- 29:22uh let's
- 29:23see look at the um documentation. So
- 29:27Roblox itself has sort of like a builtin
- 29:30hitbox sort of handler, right? So we can
- 29:33do world route which is just the whole
- 29:36game workspace. So we see something
- 29:39called get parts in part. Convenient,
- 29:42right? So
- 29:46we can say local parts found or parts
- 29:49collected for me I guess in part like
- 29:52that. And it's puts all of your little
- 29:56parameters that you want. So we want to
- 30:00detect it in the hitbox clone and you
- 30:02want prams. Even if you have no idea
- 30:05what the overlap params are, this tells
- 30:07you.
- 30:08So we need to find what overlap params
- 30:10are.
- 30:11Local params equals overlap params new.
- 30:15And you can read more about in the
- 30:17documentation, but in this case we just
- 30:19say prams.filter type
- 30:23exclude. And we want to we want the
- 30:25hitbox not to detect anything that has
- 30:28to do with the character or the actual
- 30:30hit boxes in the
- 30:32workspace. So we want to ignore that,
- 30:34but we wanted to collect everything
- 30:35else. So, we can say print parts
- 30:39collected. Oops. Like that.
- 30:43Um, let's see.
- 30:46Yeah, I'll explain the other thing
- 30:47later.
- 30:49However, now you can see that. Yep. It
- 30:52doesn't it doesn't find anything yet.
- 30:55However, if I go up here to the dummy, I
- 30:58hit it, there's something in there.
- 31:01So you'll see that everything in here is
- 31:05sort of a child within the character or
- 31:08the target that we're hitting. So right
- 31:10arm, right leg, right something like
- 31:13that. So you might be wondering how do
- 31:15we exactly get the the target right the
- 31:18actual model for the target. So in order
- 31:21to do that we can say first off we can
- 31:24uh start a loop. So underscore comma
- 31:28parts and part collects to do. So oh I
- 31:32forgot to explain this the um this sort
- 31:35of method right returns the returns a
- 31:38bunch of arrays. What arrays are is
- 31:41let's make a certain right here
- 31:44uh one test true false array one so like
- 31:50this we can say so array one corresponds
- 31:53to one array two corresponds to test
- 31:56three true four false that works so if
- 32:00we know that we can loop it like this so
- 32:04underscore the reason we do underscore
- 32:05is because we're not going to use the
- 32:07index for it The index is essentially
- 32:10one, two, three, and four. But we're
- 32:12just we're not going to worry about
- 32:13that. We're we're worrying about the
- 32:15values that are inside which are these.
- 32:19So we can
- 32:22say if
- 32:26parts. So if the part has a
- 32:30parent
- 32:32and we can find a humanoid in the parent
- 32:37then now we can say we can make a new
- 32:40variable called local target. You can
- 32:43call this whatever you want. The the
- 32:46thing you got to understand about Roblox
- 32:47is it's um very uh it's very free. You
- 32:52can do whatever you want with it.
- 32:55So knowing this we can just say local
- 32:58target hit say
- 32:59local or whatever you want but let's say
- 33:02target hit equals part.p parent which is
- 33:05the
- 33:07model and now we can say print target
- 33:13hit. So this is going to print the
- 33:16template R
- 33:20six. There we go. Like that. And you see
- 33:23there's a little pause between every M1,
- 33:26which is
- 33:27good.
- 33:28However, one thing that's going to be an
- 33:31issue is that the player is going to die
- 33:35immediately. So, let me show you why.
- 33:38So, first off, we want to get the
- 33:39humanoid local target humanoid equals
- 33:42target hit humanoid. The reason we can
- 33:44do humanoid instead of find for child,
- 33:46wait for child is because we already
- 33:48know the humanoid is there from this
- 33:52So we can do that and
- 33:55then we can say target humanoid. Let's
- 33:58go over here to our documentation
- 34:02and let's look
- 34:03at our
- 34:05humanoid. Go over here to
- 34:09methods take damage right here.
- 34:13So you can conveniently make the
- 34:16character take damage and of course
- 34:19everything protection like that. So
- 34:22we can say target humanoid take damage.
- 34:25You see that it doesn't autocomplete. So
- 34:27we can do that is through annotating. So
- 34:30the two dots and we can say that okay
- 34:32the target humanoid we know is a
- 34:34humanoid. So we can do that. Now it
- 34:37automp completes like
- 34:39so. Let's say make it take like five
- 34:41damage.
- 34:42or yeah, five damage is fine. So, if we
- 34:46play the
- 34:48game and we hit wait, let me make it
- 34:53actually show the health. So, we
- 34:55know viewer and health display always on
- 34:59like so.
- 35:01So, if we were to attack, you'll see
- 35:04that it dies right away, instantly,
- 35:06because there's no buffer between how
- 35:08many times you can hit the um target
- 35:12within a certain amount of time. So, to
- 35:14do that, we can make a new variable
- 35:18called local already hit. So, we're
- 35:20going to check if it's already been hit.
- 35:24Now we can say
- 35:30if already hits
- 35:33uh
- 35:34part.parent then return right. So,
- 35:42the reason we can't use target hit down
- 35:44here is through something called scoping
- 35:47and also how Roblox reads their um how
- 35:51Roblox how the Lua compiler reads code
- 35:53that you write. Remember, it reads it
- 35:55from up to down. So, every single line
- 35:57one by
- 35:58one. So, we know this now. So, we can't
- 36:02do target hit because it's just not
- 36:04defined yet. Even though we can see at
- 36:06face value, it's there. it's just not
- 36:07defined. So we can say part.parent or we
- 36:12can copy and paste this and move it down
- 36:14to where after you defined it and we can
- 36:17say target hit then return.
- 36:21So if we play the game, you'll see that
- 36:24there's going to be a big issue cuz it
- 36:26still dies instantly. That's because we
- 36:30didn't actually add the target to the
- 36:32table. So you can say already hit
- 36:38target hit is equal to true. And that's
- 36:41going to add a buffer to it. So you can
- 36:43only hit the same character once within
- 36:45every hit
- 36:46box. So if we walk up, we hit him. You
- 36:50see that he's being hit slowly and he's
- 36:52not being killed right away cuz for
- 36:54every hitbox uh instance it um it resets
- 36:58already hit.
- 37:00So, let's stop this. And that's pretty
- 37:05much
- 37:06uh how it's pretty much episode one for
- 37:09this tutorial.
- 37:12Um, a couple of takeaways that I want
- 37:14y'all to know is one, do not copy and
- 37:18paste. I I don't care if you say you're
- 37:19not copying and pasting. Do never copy
- 37:22and paste. You need to understand what
- 37:25exactly you're doing because that's the
- 37:27most important part. Copy and pasting.
- 37:28Sure, you can get that away in like
- 37:30Narbs and like that. Not when
- 37:32you're actually making a game. It's
- 37:34crucial that you know that. Also,
- 37:36scoping a big thing. Roblox reads things
- 37:40from up um from top to bottom. Let me
- 37:44give you another example. Scoping. Let's
- 37:46make a local function called test,
- 37:49right? And let's say local test variable
- 37:53equals
- 37:55fun. Scoping everything. What scoping
- 37:59says
- 38:00is this is a new scope. So if we were to
- 38:04say print test variable outside of this
- 38:06function, it wouldn't work cuz the
- 38:10script doesn't recognize the variable as
- 38:12a part of the rest of the um
- 38:15scope. So however, if you go in here and
- 38:19you type print test
- 38:20variable, there's no underline because
- 38:23it recognizes that test variable is in
- 38:25fact a variable in the function.
- 38:27So that's also important.
- 38:30And let's see what else. Um,
- 38:37uh, knowing it's really important that
- 38:40you know how to use documentation.
- 38:42Um, even even sometimes I use
- 38:45documentation just because I forget like
- 38:47what a method is or what it actually
- 38:48does. But just just read just read and
- 38:54you'll be able to understand way more
- 38:56and know how Roblox organization works
- 38:59and things like
- 39:00that. And that is pretty much
- 39:05it. Episode two, I'll probably get into
- 39:08how to play animations and sort of mini
- 39:11Roblox tutorials, but this is it pretty
- 39:14much.
About this transcript
This page contains the full transcript of [Part1] Easy Roblox Combat System for Beginners | (Basic Roblox Services, Hitbox Detection) by Senko, generated from the public captions YouTube serves with the video. The transcript has 5,531 words across 871 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.