YouTube2Text

[Part1.5] Roblox Combat System for Beginners | (ModuleScripts, Multi-Weapon Compatibility) — Transcript

by Senko · 2,801 words · 554 segments · language en · Watch on YouTube

Full transcript

  1. 0:00All right.
  2. 0:02This is going to be sort of episode 1.5
  3. 0:07of the combat this world series. It's
  4. 0:10not really episode two cuz episode two
  5. 0:12is going to be mainly focused on like
  6. 0:13stunning
  7. 0:15uh uh
  8. 0:16animations and things like that. But
  9. 0:18this episode is mainly going to be
  10. 0:19focused on the organization and sort of
  11. 0:21setup of that.
  12. 0:23So, we're going to be doing module
  13. 0:25scripts today. I'm going to show you how
  14. 0:27to use them.
  15. 0:29Um
  16. 0:30So, on the documentation
  17. 0:34it gives you a really clear description
  18. 0:36of a module script. So,
  19. 0:38which which you do is you use require on
  20. 0:40them. And the main
  21. 0:42takeaway or the main reason people use
  22. 0:44them is for this, don't repeat yourself.
  23. 0:47And it allows you to use
  24. 0:49um them globally. It allows you to write
  25. 0:51a function only once, but you can use it
  26. 0:53everywhere.
  27. 0:54So, for example, if I go in studio and I
  28. 0:58create a module script in replicated
  29. 1:00storage,
  30. 1:01we can call this like uh test function.
  31. 1:04All right.
  32. 1:05So, right off the bat, when you create a
  33. 1:08module script, you will see
  34. 1:10these two lines, local module and local
  35. 1:13return module.
  36. 1:16In every single module script, you
  37. 1:18always need to return something, whether
  38. 1:20it be a function or a table.
  39. 1:23So, for example, you can do return
  40. 1:24function like this.
  41. 1:27Or you can do return
  42. 1:29um empty table like this and add things
  43. 1:31inside of it.
  44. 1:33But the general rule of thumb is you
  45. 1:36just um adhere to the already um created
  46. 1:40thing.
  47. 1:41So,
  48. 1:43in order to create a function in a
  49. 1:46module script, we can do function
  50. 1:49module.that's
  51. 1:50uh let's say test function, the name of
  52. 1:52the script.
  53. 1:53And here we can say
  54. 1:55test function was called.
  55. 1:59Now, in order to be able to access the
  56. 2:01module script, it says for us to use
  57. 2:03require.
  58. 2:06So,
  59. 2:08let's say let's create a local script.
  60. 2:11And um doesn't even matter. Let's create
  61. 2:13it in
  62. 2:16StarterGui.
  63. 2:17Now,
  64. 2:18as you seen in the previous video, um
  65. 2:21you always have to instant your
  66. 2:22services.
  67. 2:24Um generally Okay, you don't need to do
  68. 2:27this, right? But, it looks much better
  69. 2:29than doing this.
  70. 2:31dot test function or anything else like
  71. 2:34that.
  72. 2:35So,
  73. 2:37generally you should do this, get
  74. 2:38service, and then
  75. 2:40Of course, remember this is on the
  76. 2:42client. So, usually things aren't fully
  77. 2:44loaded in yet. So, remember to use your
  78. 2:47uh wait for child.
  79. 2:49So, local test function module or you
  80. 2:51can call it whatever you want equals
  81. 2:52require.
  82. 2:54Yep. So, it returns the value that was
  83. 2:56returned in the module script.
  84. 2:58So, require ReplicatedStorage
  85. 3:01wait for child test function.
  86. 3:03Now,
  87. 3:04running this on its own won't do
  88. 3:07anything.
  89. 3:08In order to actually um get this to
  90. 3:10print, you need to call the function
  91. 3:12inside of here.
  92. 3:13So, we can do
  93. 3:15uh test function dot
  94. 3:17or test function module dot test
  95. 3:18function.
  96. 3:19Now, once you do that, it'll print this
  97. 3:21up. So, if we play the game,
  98. 3:25you see that test function was called.
  99. 3:28Now,
  100. 3:31um module script can store anything that
  101. 3:33you want. It does not need to be solely
  102. 3:36functions and things like that. You can
  103. 3:38store tables, for example. So, function
  104. 3:41uh
  105. 3:42module dot test table equals this.
  106. 3:46Oops, not function. Do not know why I
  107. 3:48did that, but module dot test table
  108. 3:51equals
  109. 3:52a table.
  110. 3:54Now we can add our values in here like
  111. 3:56false, true, test one, test two.
  112. 4:00And if you print out the table, so you
  113. 4:03can say print test function
  114. 4:05module.testtable.
  115. 4:07Which it auto completes for you, which
  116. 4:08is good, so you know what your actual
  117. 4:12properties of the table of the module
  118. 4:13are.
  119. 4:14Now once you print that out,
  120. 4:17you'll see that it actually prints out
  121. 4:18the table for you.
  122. 4:20So the main point I'm trying to make is
  123. 4:21that module scripts can store anything
  124. 4:23that you want. It's not only
  125. 4:26subjected to functions.
  126. 4:29Now,
  127. 4:31knowing that,
  128. 4:33we can
  129. 4:35add a lot of compatibility with
  130. 4:37different weapons in the combat system.
  131. 4:40So for example, right here,
  132. 4:43this is sort of like the generalized
  133. 4:47formula
  134. 4:49for
  135. 4:51a fist combo or any combo that you want.
  136. 4:53But let's say you have like multiple
  137. 4:55different type of combats like fist,
  138. 4:57sword, spear, dagger.
  139. 5:00You want the hit boxes,
  140. 5:03stunning, and things like that to be
  141. 5:04different.
  142. 5:06So in order to do that, we can create
  143. 5:08different module scripts that work
  144. 5:10differently.
  145. 5:13And the combat this combat system can
  146. 5:15require those module scripts to run.
  147. 5:17So let's add a folder in here
  148. 5:21called
  149. 5:23weapons.
  150. 5:25And then we can create a module script
  151. 5:27in here called fist.
  152. 5:30Now,
  153. 5:32generally I don't really like to call it
  154. 5:33local module equals this. I'd rather say
  155. 5:36local weapon type because this is what
  156. 5:39the
  157. 5:40This is a weapon type. Fist is a weapon
  158. 5:42type.
  159. 5:43So now we can create a function called
  160. 5:46weaponsType.set.
  161. 5:49Now,
  162. 5:51we can just drag all of this over
  163. 5:55into
  164. 5:58that's
  165. 6:00that's it.
  166. 6:01Now, immediately right off the bat,
  167. 6:02you'll see a lot of underscores,
  168. 6:04underlines, things like that because we
  169. 6:06need to actually reference the variables
  170. 6:09in here.
  171. 6:10So,
  172. 6:12we can say we want the
  173. 6:15character in here,
  174. 6:16which is the main thing. And you see
  175. 6:18it's underlines assets in the brief cuz
  176. 6:21we need to actually get the services
  177. 6:24and the variables, so
  178. 6:26good grief.
  179. 6:27And get the replicated storage as well.
  180. 6:33And then local assets, assets.
  181. 6:36Now, everything's fixed regarding this.
  182. 6:40Now, in order to actually cuz we don't
  183. 6:43know what type of weapon the player has
  184. 6:45yet.
  185. 6:46So, in order to do that for this type of
  186. 6:48comment system, the basics, we'll just
  187. 6:51use tools.
  188. 6:52So,
  189. 6:54let's create a tool in the starter pack
  190. 6:56called fist.
  191. 6:59Now, let's make sure that can be dropped
  192. 7:02because false cuz you don't want to drop
  193. 7:03your weapon. That's kind of stupid.
  194. 7:06So, we'll uncheck that.
  195. 7:08And we'll uncheck requires handle.
  196. 7:12Cuz requires handle what requires
  197. 7:14handles does is
  198. 7:16it expects there to be a part in here
  199. 7:18called handle that the player can hold
  200. 7:20out.
  201. 7:22So, if we turn this on and we do this,
  202. 7:27you see that there's a part that's held
  203. 7:29out. However, we don't really want a
  204. 7:31part being held out for your fist. We
  205. 7:32just want the server to be able to see
  206. 7:34what type of
  207. 7:36tool you have that corresponds to the
  208. 7:38module.
  209. 7:40So,
  210. 7:41we can uncheck requires handle.
  211. 7:44And then in here,
  212. 7:46we can keep all of this.
  213. 7:48But now we want to actually
  214. 7:51reference and require these weapon
  215. 7:53modules.
  216. 7:55So, we can say local weapon modules
  217. 7:58equals script.parent.weapons.
  218. 8:02So, hierarchically was we can this is
  219. 8:06script.parent
  220. 8:08which is systems.weapons.
  221. 8:11So, if you think if you think about it
  222. 8:12that way, you won't be you won't mess up
  223. 8:15your
  224. 8:16variable names
  225. 8:18and how you reference them.
  226. 8:20So, now we want to require them.
  227. 8:23So, we can
  228. 8:24there's something called caching which
  229. 8:26just stores all of your modules.
  230. 8:29So, we can call this cached modules
  231. 8:31equals an open table or an empty table.
  232. 8:35Then we can get the children of this
  233. 8:38folder right here and require them.
  234. 8:40So, for underscore, comma, module
  235. 8:45in weapon modules get children do.
  236. 8:49Now,
  237. 8:50what I want to point out is the
  238. 8:52difference between get children and get
  239. 8:54descendants. So,
  240. 8:57let's go over here to documentation.
  241. 9:01And let's get this right here.
  242. 9:05All right.
  243. 9:06So,
  244. 9:08essentially get children returns an
  245. 9:10array containing all of the instances
  246. 9:12direct children.
  247. 9:14So,
  248. 9:16excuse me.
  249. 9:18If you So,
  250. 9:20the direct children of this weapons
  251. 9:22folder is fist. However, if I were to
  252. 9:25add
  253. 9:26another module script in here called
  254. 9:27whatever we want whatever we want like
  255. 9:30like that.
  256. 9:32Get children won't
  257. 9:34it will skip this. It won't get that
  258. 9:36because it Because GetChildren only
  259. 9:38returns the direct children of the
  260. 9:42folder.
  261. 9:43So,
  262. 9:44however, GetDescendants returns
  263. 9:47an array containing all which everything
  264. 9:50in the instance. So, it returns
  265. 9:53a child of the child. So, if you add
  266. 9:55another module script in here, which
  267. 9:57isn't ideal, but I'm just trying to make
  268. 9:59a point,
  269. 10:00then GetDescendants will get every
  270. 10:03single module script that's available.
  271. 10:05Cool.
  272. 10:07But,
  273. 10:08GetChildren only gets the direct um
  274. 10:10instances. So, it will it will get this.
  275. 10:14It will get this.
  276. 10:16But, it won't get
  277. 10:18this.
  278. 10:21So, let's remove these, and let's go
  279. 10:23back.
  280. 10:26And then, we can say if module is a
  281. 10:28module script, then cuz we want to make
  282. 10:30sure the module is is actually a module
  283. 10:32script. Cuz if you require like a part
  284. 10:34or something, I think it's going to
  285. 10:35break. So,
  286. 10:37now we can take hash modules
  287. 10:40module.name is equal to require module.
  288. 10:44So, essentially, what
  289. 10:46this table will look like once
  290. 10:48everything is required is something like
  291. 10:50this.
  292. 10:51So, local modules required I spelled
  293. 10:53that wrong.
  294. 10:54But, fist is equal to the required
  295. 10:56module, like this.
  296. 10:59This is what the hash modules will look
  297. 11:01like once everything is required.
  298. 11:04So,
  299. 11:07let's play the game. Nothing should
  300. 11:08happen now.
  301. 11:10But,
  302. 11:12you see your um tool called fist. If you
  303. 11:15equip the tool,
  304. 11:17you see that the tool gets equipped to
  305. 11:19the character, or it gets added to the
  306. 11:20character's children.
  307. 11:23And if you unequip, it gets removed.
  308. 11:26So, using that, we can say local found
  309. 11:29tool
  310. 11:31equals character:FindFirstChild,
  311. 11:33which is tool. That should be
  312. 11:35self-explanatory.
  313. 11:37And another thing I want to point out is
  314. 11:40Roblox is severely case sensitive. So,
  315. 11:43if we do this, it will not work at all.
  316. 11:47So, always remember to either find the
  317. 11:49auto fill or
  318. 11:52uh make sure that you're not misspelling
  319. 11:54or making this lower case or anything
  320. 11:56like that.
  321. 11:58So,
  322. 11:59we say if found tool, then
  323. 12:01because you're not you can't um equip
  324. 12:04two tools at once. You can only equip
  325. 12:05one.
  326. 12:07So, this is uh this is effective because
  327. 12:09of that.
  328. 12:11So, now let's check if the cached
  329. 12:13modules has the tool in it. In this
  330. 12:15case, fist would be fist corresponding
  331. 12:17to the weapons module.
  332. 12:20So, local um
  333. 12:22if found tool, then
  334. 12:23local found module equals cached modules
  335. 12:27found tool.name,
  336. 12:29which is fist, the name of the tool.
  337. 12:32So, if
  338. 12:33found module,
  339. 12:35then found module.attack.
  340. 12:38And then, of course, since we need a
  341. 12:41character
  342. 12:43um argument passed in here, we need to
  343. 12:45pass the character in here. Like so.
  344. 12:49Now,
  345. 12:50I want to point out that this variable
  346. 12:52can be named anything. It can be named
  347. 12:54this, abba abba babba, whatever.
  348. 12:58It doesn't affect um the argument that
  349. 13:00you pass in here.
  350. 13:02This is this the name of this is solely
  351. 13:04for you to know what you're referencing,
  352. 13:06which is the character.
  353. 13:10So,
  354. 13:11once we do this, it should work.
  355. 13:14So, if we play the game,
  356. 13:17you see that if we hold left click,
  357. 13:18nothing happens.
  358. 13:20But if we equip the tool,
  359. 13:21and we hold it, it works.
  360. 13:25And of course, if you walk up to here,
  361. 13:27you see that he's taking damage slowly.
  362. 13:30However, if I unequip the sword, then it
  363. 13:32stops hitting.
  364. 13:35So, that is good.
  365. 13:38Now,
  366. 13:39what we also want to do is
  367. 13:42make a weapons data module in the
  368. 13:45replicated storage.
  369. 13:48So, essentially weapon data will hold
  370. 13:50all of the shared data, which I
  371. 13:53mentioned in the other video,
  372. 13:55between that we want the client and
  373. 13:57server to access at the same time.
  374. 13:59So, we can call this local weapon data.
  375. 14:03Return weapon data.
  376. 14:06And then,
  377. 14:08we also
  378. 14:09uh oh, one thing.
  379. 14:11Hold on, let me name this weapon data
  380. 14:13module.
  381. 14:15One thing I want to notice um that's for
  382. 14:16y'all is
  383. 14:19if there is a
  384. 14:23sort of
  385. 14:24uh loop or anything
  386. 14:27in here that's not a function,
  387. 14:30then
  388. 14:33once you you will need to require it for
  389. 14:35it to run, basically.
  390. 14:37So, what I mean is, let's say uh print
  391. 14:40hi.
  392. 14:42Uh
  393. 14:45uh let's say it's something like this.
  394. 14:47Yeah. So, print hi.
  395. 14:50This print will print regardless whether
  396. 14:53you call a function or anything like
  397. 14:55that.
  398. 14:55It will print immediately once you
  399. 14:56require it.
  400. 14:58So, if I were to require weapon data,
  401. 15:00let's reference it.
  402. 15:05And let's do uh local
  403. 15:08weapon data equals require
  404. 15:13So, you see, once I require it, it'll
  405. 15:15immediately print hi, like that.
  406. 15:19So, knowing that, we can
  407. 15:21create a ton of modules in here. Let's
  408. 15:23call this fist, which will hold the
  409. 15:25shared data for fist.
  410. 15:28And then we can say for underscore
  411. 15:30common module and script get children do
  412. 15:34uh just the same thing as the server
  413. 15:36side.
  414. 15:37Then
  415. 15:39stored
  416. 15:40uh
  417. 15:41stored data. Let's call it that.
  418. 15:44Ma weapon data that stored data module
  419. 15:47that name equals require module.
  420. 15:51Uh it's essentially the same thing as we
  421. 15:52did up here.
  422. 15:54Uh we're just trying to store all of
  423. 15:55these modules that are soon to be added.
  424. 15:58So now in here we can store things like
  425. 16:00how much damage you want it to.
  426. 16:02So module damage is equal to let's say
  427. 16:0510 or 20.
  428. 16:09Now we exit out of the script.
  429. 16:13And then you'll notice that if we do
  430. 16:15print weapon data that stored data,
  431. 16:19it'll print out all of the data that was
  432. 16:21required. Because remember Roblox
  433. 16:23compiler always runs from the top to the
  434. 16:26bottom.
  435. 16:27So first line to the very last line. So
  436. 16:29this will run um in a in a sequential
  437. 16:31order.
  438. 16:33So if I play the game,
  439. 16:35you'll see that everything is required.
  440. 16:37So damage equals 20.
  441. 16:41So
  442. 16:44if I were to
  443. 16:47exit out of this or remove the print
  444. 16:51and go to
  445. 16:52the um
  446. 16:54fist attacking module,
  447. 16:56we can require weapon data.
  448. 17:06Now,
  449. 17:07you might be wondering how do we access
  450. 17:09the fist module or the shared fist
  451. 17:11module?
  452. 17:12So one way we can do that is by just
  453. 17:14saying local fist module
  454. 17:16dot stored data dot fist.
  455. 17:19That's sort of um inefficient way.
  456. 17:22Not inefficient, but it doesn't look
  457. 17:23great.
  458. 17:25So, one way we could do it is do
  459. 17:27function weapon data
  460. 17:30dot
  461. 17:32gets
  462. 17:33uh weapon data
  463. 17:34like so.
  464. 17:36Now, we can say weapon name up it auto
  465. 17:38completed, but weapon name string.
  466. 17:41Now, remember the previous video I
  467. 17:42discussed about annotations.
  468. 17:45Which essentially tells um
  469. 17:49the compiler what type of data type the
  470. 17:52weapon name is, which in this case is
  471. 17:54it's a string.
  472. 17:56So, we can say return weapon data dot
  473. 17:59store data
  474. 18:01weapon name
  475. 18:03or no.
  476. 18:04So, if it finds it, then it returns it,
  477. 18:07otherwise it just returns no.
  478. 18:09So, now we can say
  479. 18:13local
  480. 18:16Oops, wrong script. In the fist module
  481. 18:20we can say
  482. 18:21local
  483. 18:26Uh let's let's do this. Instead of um
  484. 18:29doing require, we can say require dot
  485. 18:33get weapon data
  486. 18:35like so.
  487. 18:39Now, we can say require get weapon data
  488. 18:42script dot name.
  489. 18:45So, essentially we're getting the fist
  490. 18:48shared weapon data
  491. 18:50right here.
  492. 18:51So, now
  493. 18:53we can scroll down here and replace the
  494. 18:56tick damage with the value in here, the
  495. 18:58damage value in here.
  496. 19:01So, we can say weapon data dot damage
  497. 19:05like so.
  498. 19:08Now, if we're to play the game
  499. 19:12we'll see that should
  500. 19:1320 damage per. Yep.
  501. 19:15Like so.
  502. 19:18So,
  503. 19:20this is efficient in um one or two ways.
  504. 19:22For one, you don't need to scroll
  505. 19:24through a long script, especially when
  506. 19:26we add things like animations, stunning,
  507. 19:28and things like that. You don't want to
  508. 19:30scroll through like 300 or 400 lines
  509. 19:33just to find take damage and change it
  510. 19:35to like five, 10, or 20, or something
  511. 19:38like that.
  512. 19:39All you need to do is go to the weapon
  513. 19:42data module and change in here.
  514. 19:44So, we can say change it to like one
  515. 19:46damage or something like that.
  516. 19:48In the future, we can also add things
  517. 19:50like module.stunt
  518. 19:53time equals like 0.25 seconds, things
  519. 19:55like that.
  520. 19:57But, for now, we'll just focus on
  521. 19:59damaging and the rest in the later
  522. 20:01videos.
  523. 20:03So, we play the game knowing that we
  524. 20:05changed it to one,
  525. 20:07you'll see that
  526. 20:10health is reduced to very slowly.
  527. 20:14Like so.
  528. 20:17Now,
  529. 20:19that should be I think that wraps up the
  530. 20:21end of this video.
  531. 20:23It was kind of short in a way, but
  532. 20:25that's kind of because I have exams
  533. 20:27tomorrow.
  534. 20:29But, I just wanted to get a video out
  535. 20:30just for y'all to
  536. 20:33understand how module scripts work and
  537. 20:35what you can do with them, how efficient
  538. 20:36they are.
  539. 20:37So, you don't do the um so, you can
  540. 20:41adhere to the don't repeat yourself
  541. 20:43principle.
  542. 20:45So, you don't need to spam functions,
  543. 20:47anything like that. You'll just
  544. 20:48reference the module script once and
  545. 20:51call the function.
  546. 20:52Like so, get weapon data here, and then
  547. 20:54you can
  548. 20:56just get weapon data like that.
  549. 20:59And that's pretty much it. This video
  550. 21:03was just sort of organization purposes
  551. 21:05for the future.
  552. 21:07But, yeah, the next video I'll show you
  553. 21:10how to do stunning, handling animations,
  554. 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.