[Part1.5] Roblox Combat System for Beginners | (ModuleScripts, Multi-Weapon Compatibility) — Transcript
Full transcript
- 0:00All right.
- 0:02This is going to be sort of episode 1.5
- 0:07of the combat this world series. It's
- 0:10not really episode two cuz episode two
- 0:12is going to be mainly focused on like
- 0:13stunning
- 0:15uh uh
- 0:16animations and things like that. But
- 0:18this episode is mainly going to be
- 0:19focused on the organization and sort of
- 0:21setup of that.
- 0:23So, we're going to be doing module
- 0:25scripts today. I'm going to show you how
- 0:27to use them.
- 0:29Um
- 0:30So, on the documentation
- 0:34it gives you a really clear description
- 0:36of a module script. So,
- 0:38which which you do is you use require on
- 0:40them. And the main
- 0:42takeaway or the main reason people use
- 0:44them is for this, don't repeat yourself.
- 0:47And it allows you to use
- 0:49um them globally. It allows you to write
- 0:51a function only once, but you can use it
- 0:53everywhere.
- 0:54So, for example, if I go in studio and I
- 0:58create a module script in replicated
- 1:00storage,
- 1:01we can call this like uh test function.
- 1:04All right.
- 1:05So, right off the bat, when you create a
- 1:08module script, you will see
- 1:10these two lines, local module and local
- 1:13return module.
- 1:16In every single module script, you
- 1:18always need to return something, whether
- 1:20it be a function or a table.
- 1:23So, for example, you can do return
- 1:24function like this.
- 1:27Or you can do return
- 1:29um empty table like this and add things
- 1:31inside of it.
- 1:33But the general rule of thumb is you
- 1:36just um adhere to the already um created
- 1:40thing.
- 1:41So,
- 1:43in order to create a function in a
- 1:46module script, we can do function
- 1:49module.that's
- 1:50uh let's say test function, the name of
- 1:52the script.
- 1:53And here we can say
- 1:55test function was called.
- 1:59Now, in order to be able to access the
- 2:01module script, it says for us to use
- 2:03require.
- 2:06So,
- 2:08let's say let's create a local script.
- 2:11And um doesn't even matter. Let's create
- 2:13it in
- 2:16StarterGui.
- 2:17Now,
- 2:18as you seen in the previous video, um
- 2:21you always have to instant your
- 2:22services.
- 2:24Um generally Okay, you don't need to do
- 2:27this, right? But, it looks much better
- 2:29than doing this.
- 2:31dot test function or anything else like
- 2:34that.
- 2:35So,
- 2:37generally you should do this, get
- 2:38service, and then
- 2:40Of course, remember this is on the
- 2:42client. So, usually things aren't fully
- 2:44loaded in yet. So, remember to use your
- 2:47uh wait for child.
- 2:49So, local test function module or you
- 2:51can call it whatever you want equals
- 2:52require.
- 2:54Yep. So, it returns the value that was
- 2:56returned in the module script.
- 2:58So, require ReplicatedStorage
- 3:01wait for child test function.
- 3:03Now,
- 3:04running this on its own won't do
- 3:07anything.
- 3:08In order to actually um get this to
- 3:10print, you need to call the function
- 3:12inside of here.
- 3:13So, we can do
- 3:15uh test function dot
- 3:17or test function module dot test
- 3:18function.
- 3:19Now, once you do that, it'll print this
- 3:21up. So, if we play the game,
- 3:25you see that test function was called.
- 3:28Now,
- 3:31um module script can store anything that
- 3:33you want. It does not need to be solely
- 3:36functions and things like that. You can
- 3:38store tables, for example. So, function
- 3:41uh
- 3:42module dot test table equals this.
- 3:46Oops, not function. Do not know why I
- 3:48did that, but module dot test table
- 3:51equals
- 3:52a table.
- 3:54Now we can add our values in here like
- 3:56false, true, test one, test two.
- 4:00And if you print out the table, so you
- 4:03can say print test function
- 4:05module.testtable.
- 4:07Which it auto completes for you, which
- 4:08is good, so you know what your actual
- 4:12properties of the table of the module
- 4:13are.
- 4:14Now once you print that out,
- 4:17you'll see that it actually prints out
- 4:18the table for you.
- 4:20So the main point I'm trying to make is
- 4:21that module scripts can store anything
- 4:23that you want. It's not only
- 4:26subjected to functions.
- 4:29Now,
- 4:31knowing that,
- 4:33we can
- 4:35add a lot of compatibility with
- 4:37different weapons in the combat system.
- 4:40So for example, right here,
- 4:43this is sort of like the generalized
- 4:47formula
- 4:49for
- 4:51a fist combo or any combo that you want.
- 4:53But let's say you have like multiple
- 4:55different type of combats like fist,
- 4:57sword, spear, dagger.
- 5:00You want the hit boxes,
- 5:03stunning, and things like that to be
- 5:04different.
- 5:06So in order to do that, we can create
- 5:08different module scripts that work
- 5:10differently.
- 5:13And the combat this combat system can
- 5:15require those module scripts to run.
- 5:17So let's add a folder in here
- 5:21called
- 5:23weapons.
- 5:25And then we can create a module script
- 5:27in here called fist.
- 5:30Now,
- 5:32generally I don't really like to call it
- 5:33local module equals this. I'd rather say
- 5:36local weapon type because this is what
- 5:39the
- 5:40This is a weapon type. Fist is a weapon
- 5:42type.
- 5:43So now we can create a function called
- 5:46weaponsType.set.
- 5:49Now,
- 5:51we can just drag all of this over
- 5:55into
- 5:58that's
- 6:00that's it.
- 6:01Now, immediately right off the bat,
- 6:02you'll see a lot of underscores,
- 6:04underlines, things like that because we
- 6:06need to actually reference the variables
- 6:09in here.
- 6:10So,
- 6:12we can say we want the
- 6:15character in here,
- 6:16which is the main thing. And you see
- 6:18it's underlines assets in the brief cuz
- 6:21we need to actually get the services
- 6:24and the variables, so
- 6:26good grief.
- 6:27And get the replicated storage as well.
- 6:33And then local assets, assets.
- 6:36Now, everything's fixed regarding this.
- 6:40Now, in order to actually cuz we don't
- 6:43know what type of weapon the player has
- 6:45yet.
- 6:46So, in order to do that for this type of
- 6:48comment system, the basics, we'll just
- 6:51use tools.
- 6:52So,
- 6:54let's create a tool in the starter pack
- 6:56called fist.
- 6:59Now, let's make sure that can be dropped
- 7:02because false cuz you don't want to drop
- 7:03your weapon. That's kind of stupid.
- 7:06So, we'll uncheck that.
- 7:08And we'll uncheck requires handle.
- 7:12Cuz requires handle what requires
- 7:14handles does is
- 7:16it expects there to be a part in here
- 7:18called handle that the player can hold
- 7:20out.
- 7:22So, if we turn this on and we do this,
- 7:27you see that there's a part that's held
- 7:29out. However, we don't really want a
- 7:31part being held out for your fist. We
- 7:32just want the server to be able to see
- 7:34what type of
- 7:36tool you have that corresponds to the
- 7:38module.
- 7:40So,
- 7:41we can uncheck requires handle.
- 7:44And then in here,
- 7:46we can keep all of this.
- 7:48But now we want to actually
- 7:51reference and require these weapon
- 7:53modules.
- 7:55So, we can say local weapon modules
- 7:58equals script.parent.weapons.
- 8:02So, hierarchically was we can this is
- 8:06script.parent
- 8:08which is systems.weapons.
- 8:11So, if you think if you think about it
- 8:12that way, you won't be you won't mess up
- 8:15your
- 8:16variable names
- 8:18and how you reference them.
- 8:20So, now we want to require them.
- 8:23So, we can
- 8:24there's something called caching which
- 8:26just stores all of your modules.
- 8:29So, we can call this cached modules
- 8:31equals an open table or an empty table.
- 8:35Then we can get the children of this
- 8:38folder right here and require them.
- 8:40So, for underscore, comma, module
- 8:45in weapon modules get children do.
- 8:49Now,
- 8:50what I want to point out is the
- 8:52difference between get children and get
- 8:54descendants. So,
- 8:57let's go over here to documentation.
- 9:01And let's get this right here.
- 9:05All right.
- 9:06So,
- 9:08essentially get children returns an
- 9:10array containing all of the instances
- 9:12direct children.
- 9:14So,
- 9:16excuse me.
- 9:18If you So,
- 9:20the direct children of this weapons
- 9:22folder is fist. However, if I were to
- 9:25add
- 9:26another module script in here called
- 9:27whatever we want whatever we want like
- 9:30like that.
- 9:32Get children won't
- 9:34it will skip this. It won't get that
- 9:36because it Because GetChildren only
- 9:38returns the direct children of the
- 9:42folder.
- 9:43So,
- 9:44however, GetDescendants returns
- 9:47an array containing all which everything
- 9:50in the instance. So, it returns
- 9:53a child of the child. So, if you add
- 9:55another module script in here, which
- 9:57isn't ideal, but I'm just trying to make
- 9:59a point,
- 10:00then GetDescendants will get every
- 10:03single module script that's available.
- 10:05Cool.
- 10:07But,
- 10:08GetChildren only gets the direct um
- 10:10instances. So, it will it will get this.
- 10:14It will get this.
- 10:16But, it won't get
- 10:18this.
- 10:21So, let's remove these, and let's go
- 10:23back.
- 10:26And then, we can say if module is a
- 10:28module script, then cuz we want to make
- 10:30sure the module is is actually a module
- 10:32script. Cuz if you require like a part
- 10:34or something, I think it's going to
- 10:35break. So,
- 10:37now we can take hash modules
- 10:40module.name is equal to require module.
- 10:44So, essentially, what
- 10:46this table will look like once
- 10:48everything is required is something like
- 10:50this.
- 10:51So, local modules required I spelled
- 10:53that wrong.
- 10:54But, fist is equal to the required
- 10:56module, like this.
- 10:59This is what the hash modules will look
- 11:01like once everything is required.
- 11:04So,
- 11:07let's play the game. Nothing should
- 11:08happen now.
- 11:10But,
- 11:12you see your um tool called fist. If you
- 11:15equip the tool,
- 11:17you see that the tool gets equipped to
- 11:19the character, or it gets added to the
- 11:20character's children.
- 11:23And if you unequip, it gets removed.
- 11:26So, using that, we can say local found
- 11:29tool
- 11:31equals character:FindFirstChild,
- 11:33which is tool. That should be
- 11:35self-explanatory.
- 11:37And another thing I want to point out is
- 11:40Roblox is severely case sensitive. So,
- 11:43if we do this, it will not work at all.
- 11:47So, always remember to either find the
- 11:49auto fill or
- 11:52uh make sure that you're not misspelling
- 11:54or making this lower case or anything
- 11:56like that.
- 11:58So,
- 11:59we say if found tool, then
- 12:01because you're not you can't um equip
- 12:04two tools at once. You can only equip
- 12:05one.
- 12:07So, this is uh this is effective because
- 12:09of that.
- 12:11So, now let's check if the cached
- 12:13modules has the tool in it. In this
- 12:15case, fist would be fist corresponding
- 12:17to the weapons module.
- 12:20So, local um
- 12:22if found tool, then
- 12:23local found module equals cached modules
- 12:27found tool.name,
- 12:29which is fist, the name of the tool.
- 12:32So, if
- 12:33found module,
- 12:35then found module.attack.
- 12:38And then, of course, since we need a
- 12:41character
- 12:43um argument passed in here, we need to
- 12:45pass the character in here. Like so.
- 12:49Now,
- 12:50I want to point out that this variable
- 12:52can be named anything. It can be named
- 12:54this, abba abba babba, whatever.
- 12:58It doesn't affect um the argument that
- 13:00you pass in here.
- 13:02This is this the name of this is solely
- 13:04for you to know what you're referencing,
- 13:06which is the character.
- 13:10So,
- 13:11once we do this, it should work.
- 13:14So, if we play the game,
- 13:17you see that if we hold left click,
- 13:18nothing happens.
- 13:20But if we equip the tool,
- 13:21and we hold it, it works.
- 13:25And of course, if you walk up to here,
- 13:27you see that he's taking damage slowly.
- 13:30However, if I unequip the sword, then it
- 13:32stops hitting.
- 13:35So, that is good.
- 13:38Now,
- 13:39what we also want to do is
- 13:42make a weapons data module in the
- 13:45replicated storage.
- 13:48So, essentially weapon data will hold
- 13:50all of the shared data, which I
- 13:53mentioned in the other video,
- 13:55between that we want the client and
- 13:57server to access at the same time.
- 13:59So, we can call this local weapon data.
- 14:03Return weapon data.
- 14:06And then,
- 14:08we also
- 14:09uh oh, one thing.
- 14:11Hold on, let me name this weapon data
- 14:13module.
- 14:15One thing I want to notice um that's for
- 14:16y'all is
- 14:19if there is a
- 14:23sort of
- 14:24uh loop or anything
- 14:27in here that's not a function,
- 14:30then
- 14:33once you you will need to require it for
- 14:35it to run, basically.
- 14:37So, what I mean is, let's say uh print
- 14:40hi.
- 14:42Uh
- 14:45uh let's say it's something like this.
- 14:47Yeah. So, print hi.
- 14:50This print will print regardless whether
- 14:53you call a function or anything like
- 14:55that.
- 14:55It will print immediately once you
- 14:56require it.
- 14:58So, if I were to require weapon data,
- 15:00let's reference it.
- 15:05And let's do uh local
- 15:08weapon data equals require
- 15:13So, you see, once I require it, it'll
- 15:15immediately print hi, like that.
- 15:19So, knowing that, we can
- 15:21create a ton of modules in here. Let's
- 15:23call this fist, which will hold the
- 15:25shared data for fist.
- 15:28And then we can say for underscore
- 15:30common module and script get children do
- 15:34uh just the same thing as the server
- 15:36side.
- 15:37Then
- 15:39stored
- 15:40uh
- 15:41stored data. Let's call it that.
- 15:44Ma weapon data that stored data module
- 15:47that name equals require module.
- 15:51Uh it's essentially the same thing as we
- 15:52did up here.
- 15:54Uh we're just trying to store all of
- 15:55these modules that are soon to be added.
- 15:58So now in here we can store things like
- 16:00how much damage you want it to.
- 16:02So module damage is equal to let's say
- 16:0510 or 20.
- 16:09Now we exit out of the script.
- 16:13And then you'll notice that if we do
- 16:15print weapon data that stored data,
- 16:19it'll print out all of the data that was
- 16:21required. Because remember Roblox
- 16:23compiler always runs from the top to the
- 16:26bottom.
- 16:27So first line to the very last line. So
- 16:29this will run um in a in a sequential
- 16:31order.
- 16:33So if I play the game,
- 16:35you'll see that everything is required.
- 16:37So damage equals 20.
- 16:41So
- 16:44if I were to
- 16:47exit out of this or remove the print
- 16:51and go to
- 16:52the um
- 16:54fist attacking module,
- 16:56we can require weapon data.
- 17:06Now,
- 17:07you might be wondering how do we access
- 17:09the fist module or the shared fist
- 17:11module?
- 17:12So one way we can do that is by just
- 17:14saying local fist module
- 17:16dot stored data dot fist.
- 17:19That's sort of um inefficient way.
- 17:22Not inefficient, but it doesn't look
- 17:23great.
- 17:25So, one way we could do it is do
- 17:27function weapon data
- 17:30dot
- 17:32gets
- 17:33uh weapon data
- 17:34like so.
- 17:36Now, we can say weapon name up it auto
- 17:38completed, but weapon name string.
- 17:41Now, remember the previous video I
- 17:42discussed about annotations.
- 17:45Which essentially tells um
- 17:49the compiler what type of data type the
- 17:52weapon name is, which in this case is
- 17:54it's a string.
- 17:56So, we can say return weapon data dot
- 17:59store data
- 18:01weapon name
- 18:03or no.
- 18:04So, if it finds it, then it returns it,
- 18:07otherwise it just returns no.
- 18:09So, now we can say
- 18:13local
- 18:16Oops, wrong script. In the fist module
- 18:20we can say
- 18:21local
- 18:26Uh let's let's do this. Instead of um
- 18:29doing require, we can say require dot
- 18:33get weapon data
- 18:35like so.
- 18:39Now, we can say require get weapon data
- 18:42script dot name.
- 18:45So, essentially we're getting the fist
- 18:48shared weapon data
- 18:50right here.
- 18:51So, now
- 18:53we can scroll down here and replace the
- 18:56tick damage with the value in here, the
- 18:58damage value in here.
- 19:01So, we can say weapon data dot damage
- 19:05like so.
- 19:08Now, if we're to play the game
- 19:12we'll see that should
- 19:1320 damage per. Yep.
- 19:15Like so.
- 19:18So,
- 19:20this is efficient in um one or two ways.
- 19:22For one, you don't need to scroll
- 19:24through a long script, especially when
- 19:26we add things like animations, stunning,
- 19:28and things like that. You don't want to
- 19:30scroll through like 300 or 400 lines
- 19:33just to find take damage and change it
- 19:35to like five, 10, or 20, or something
- 19:38like that.
- 19:39All you need to do is go to the weapon
- 19:42data module and change in here.
- 19:44So, we can say change it to like one
- 19:46damage or something like that.
- 19:48In the future, we can also add things
- 19:50like module.stunt
- 19:53time equals like 0.25 seconds, things
- 19:55like that.
- 19:57But, for now, we'll just focus on
- 19:59damaging and the rest in the later
- 20:01videos.
- 20:03So, we play the game knowing that we
- 20:05changed it to one,
- 20:07you'll see that
- 20:10health is reduced to very slowly.
- 20:14Like so.
- 20:17Now,
- 20:19that should be I think that wraps up the
- 20:21end of this video.
- 20:23It was kind of short in a way, but
- 20:25that's kind of because I have exams
- 20:27tomorrow.
- 20:29But, I just wanted to get a video out
- 20:30just for y'all to
- 20:33understand how module scripts work and
- 20:35what you can do with them, how efficient
- 20:36they are.
- 20:37So, you don't do the um so, you can
- 20:41adhere to the don't repeat yourself
- 20:43principle.
- 20:45So, you don't need to spam functions,
- 20:47anything like that. You'll just
- 20:48reference the module script once and
- 20:51call the function.
- 20:52Like so, get weapon data here, and then
- 20:54you can
- 20:56just get weapon data like that.
- 20:59And that's pretty much it. This video
- 21:03was just sort of organization purposes
- 21:05for the future.
- 21:07But, yeah, the next video I'll show you
- 21:10how to do stunning, handling animations,
- 21:13and things like that.
About this transcript
This page contains the full transcript of [Part1.5] Roblox Combat System for Beginners | (ModuleScripts, Multi-Weapon Compatibility) by Senko, generated from the public captions YouTube serves with the video. The transcript has 2,801 words across 554 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.