YouTube2Text

[Part1] Easy Roblox Combat System for Beginners | (Basic Roblox Services, Hitbox Detection) — Transcript

by Senko · 5,531 words · 871 segments · language en · Watch on YouTube

Full transcript

  1. 0:00All right. So, um the first video I just
  2. 0:03didn't press record, so this is going to
  3. 0:06be a second time. Uh this video should
  4. 0:09be around 40 minutes. And this is going
  5. 0:10to show you like the basics of how to
  6. 0:12make a combat system. And that's pretty
  7. 0:16much it. I'm also going to show you how
  8. 0:17Roblox um works in general, how Roblox
  9. 0:20Studio works, and how um it's sort of an
  10. 0:23objectoriented type of um compiler type
  11. 0:25of system. So, yeah.
  12. 0:30So, first things first, let's look at
  13. 0:32the starter character.
  14. 0:35So, if we play the game, we'll notice
  15. 0:37that workspace, which is the whole thing
  16. 0:39over here, has an object called me. This
  17. 0:43is your
  18. 0:44character. If you open your character,
  19. 0:47this these are all the children of that
  20. 0:49character. Vice versa, the children,
  21. 0:52this is the parent of the child. So
  22. 0:55human repart is a child of my character.
  23. 0:59So
  24. 1:01another thing we want to note is starter
  25. 1:04character scripts. Anything and I mean
  26. 1:06anything that you put in here is going
  27. 1:09to be replicated to your character. So
  28. 1:12let's make a folder called core. Right?
  29. 1:14This is going to be for organization
  30. 1:15type of
  31. 1:16preferences. So if you play the game,
  32. 1:18you'll notice that your character
  33. 1:20automatically has a folder called core.
  34. 1:24So, you might be thinking, okay, there's
  35. 1:26something called starter player scripts
  36. 1:28here, too.
  37. 1:30So, yes, it does the same exact thing.
  38. 1:32If we add a folder here called starter
  39. 1:36player
  40. 1:37scripts, or I'm not going to name it
  41. 1:39that. Uh, something something like that.
  42. 1:42Play the game. If you look at your
  43. 1:44player, you open player scripts, you'll
  44. 1:47see a folder in there called whatever
  45. 1:50brain rod that is. So,
  46. 1:53Let's get started with the actual
  47. 1:55scripting portion. We'll call this uh
  48. 1:59inputs. You can call this whatever you
  49. 2:00want.
  50. 2:03So, let's uh first thing I want to note
  51. 2:06for y'all is comments. Two dashes equals
  52. 2:09a comment. So, you can write whatever
  53. 2:11you want here, but you can't do it once
  54. 2:13you enter a new line. In order to do
  55. 2:15that, we want two dashes and the little
  56. 2:18um letter beside the P. So we want to do
  57. 2:22that twice. One, two. And then you can
  58. 2:24press enter. Anything within this little
  59. 2:27white space here, you can type. So you
  60. 2:28test test test. Doesn't matter. It's
  61. 2:31useful for commenting for other people
  62. 2:33and yourself to know just how the script
  63. 2:36works in general. What what function
  64. 2:38does what. So let's call this uh core
  65. 2:41input client.
  66. 2:43Now, the first thing I want to emphasize
  67. 2:47for y'all is the the supreme usefulness
  68. 2:49of uh
  69. 2:52documentation. So, you'll notice that
  70. 2:54for pretty much every combat system
  71. 2:59uh well, a good one, you can hold your
  72. 3:02left mouse button to go a punch.
  73. 3:05So, to do that, we'll use something
  74. 3:07called run service
  75. 3:09right here.
  76. 3:11So,
  77. 3:13One thing I want youall to note too is
  78. 3:15the difference between events and
  79. 3:17properties or events and methods. So
  80. 3:21events will always have a period
  81. 3:24following their calling and methods will
  82. 3:27always have the two double dots. So
  83. 3:31let's define your variable called run
  84. 3:33service
  85. 3:35and let's look at the events called
  86. 3:39render stepped.
  87. 3:42So you'll see that it gives you a little
  88. 3:44description of it. Fires every frame
  89. 3:46prior to the frame being rendered. So
  90. 3:49this is good because now we can actually
  91. 3:51detect um continuously if the player is
  92. 3:55holding your left mouse button. So we
  93. 3:57can say run service dot which is an
  94. 4:00event render stepped after every event.
  95. 4:04It's going to be a muscle memory once
  96. 4:05you do it for like a while. But you
  97. 4:06always have a connect function open
  98. 4:09parenthesis and whatever like the
  99. 4:11arguments that the default Roblox
  100. 4:13function has for you which in this case
  101. 4:16we call delta
  102. 4:17time. It does not need to be called
  103. 4:19this. You can call it dt ab some brain
  104. 4:24rot but in this case we just do delta
  105. 4:26time. Another thing we can note is
  106. 4:29annotations. So this tells Roblox that
  107. 4:33this type of argument is a number. You
  108. 4:36can call this is a string is um a
  109. 4:40boolean but in this case it's going to
  110. 4:42be a number.
  111. 4:44So now we want to also look at a service
  112. 4:47called user input
  113. 4:50service. Every single game ever uses
  114. 4:53input service. So if we look at a method
  115. 4:58and we score down called is mouse button
  116. 5:01pressed. It conveniently has a way for
  117. 5:04you to check if your mouse button is
  118. 5:05pressed and it returns
  119. 5:07whatever doesn't matter. The
  120. 5:09documentation has it all for you. So we
  121. 5:13can say we have to define the service
  122. 5:15first like
  123. 5:18so and then we can say if user service
  124. 5:22is mouse button pressed a method once
  125. 5:24again. So these double
  126. 5:26dots enum user input type button one.
  127. 5:30Even if you don't know what enums are,
  128. 5:32user input types are the documentation
  129. 5:36tells you. It tells you exactly what
  130. 5:37enums are, default values, etc., etc. So
  131. 5:42we can say this and we can say print.
  132. 5:45Obviously you should know what prints
  133. 5:46are. So prints
  134. 5:49um clients left click.
  135. 5:52So,
  136. 5:54we play the game and if we left click or
  137. 5:58hold down left click, we can see that it
  138. 6:01prints it up. And if I let go, it stops
  139. 6:04printing all all from what? Four
  140. 6:08lines. So, I don't know why games don't
  141. 6:11know how to do it. It's dead ass. Just
  142. 6:13four lines, bro. See, it's still
  143. 6:15recording. Yep.
  144. 6:17So the next thing we want is
  145. 6:21um to notes uh replicated storage and
  146. 6:25all of these folders I have in here.
  147. 6:27Once again organization um purposes
  148. 6:30preferences doesn't really matter but we
  149. 6:34will reference remotes like so. And in
  150. 6:38doing so I'm going to show yall what the
  151. 6:39difference is between wait for child and
  152. 6:42find for child.
  153. 6:44The main difference is wait for child
  154. 6:47yields the script
  155. 6:49and find first child immediately
  156. 6:52attempts to um attempts to find the
  157. 6:55argument passed which is a string.
  158. 6:59So what yielding does right
  159. 7:03and why it's so crucial is if you do
  160. 7:05workspace wait for child blah blah
  161. 7:08blah everything beneath this will not
  162. 7:11run.
  163. 7:12So works whiffer child is used in the
  164. 7:17assumption that the child that you're
  165. 7:19trying to find is going to be added some
  166. 7:21time or another.
  167. 7:23But the default cutout time is around 5
  168. 7:26seconds. I think three or four or five
  169. 7:28seconds. So if I do play you and I hold
  170. 7:32left click, you'll see that it doesn't
  171. 7:33work
  172. 7:35and an infinite yield should pop up.
  173. 7:37There you go. So you see infinite yield
  174. 7:40possible because it just wasn't there.
  175. 7:44So yeah.
  176. 7:48Now and knowing that we will do local
  177. 7:52replicated
  178. 7:53storage game get service cuz we want a
  179. 7:56way for the client to communicate with
  180. 7:58the server saying that okay I want to um
  181. 8:03attack.
  182. 8:05So we'll say local remotes equals
  183. 8:07replicate storage wait for child
  184. 8:09remotes. The reason we do this is
  185. 8:12because the client doesn't load all
  186. 8:15these right away. For every new client
  187. 8:18that's added, it needs to load every
  188. 8:19single thing replicated storage. So if
  189. 8:21you do dot remotes, it will it will
  190. 8:25error occasionally depending on your
  191. 8:26ping. So to be safe, we'll wait for
  192. 8:28child
  193. 8:29remotes. So now we'll make a new remote
  194. 8:33event
  195. 8:35called attack.
  196. 8:37So, I don't know if you gotten far in
  197. 8:39the YouTube videos yet, but what remote
  198. 8:42events do is they let you communicate
  199. 8:43from the client to the server.
  200. 8:47So, we'll say remotes attack fire server
  201. 8:51like so. And once again, if you don't
  202. 8:55know what remote events are,
  203. 8:56conveniently, we have something called
  204. 8:58remote
  205. 9:00event. So, you have methods, which once
  206. 9:03again double dots. events once again are
  207. 9:06single
  208. 9:07dots. Let me get some
  209. 9:12more.
  210. 9:14Now we're going to make a script in the
  211. 9:17systems once again. Organization
  212. 9:19preferences. We'll call this comt
  213. 9:22system.
  214. 9:24Now comments just for me. And then we'll
  215. 9:28say local replicated storage because we
  216. 9:32want to get we want to reference the
  217. 9:34remote uh remotes folder. So we'll get
  218. 9:38service and then we'll say local remotes
  219. 9:41equals storage
  220. 9:44remotes. So the reason we do that is be
  221. 9:47it's just it's just for pure looks man
  222. 9:50pure organization cuz this looks ugly
  223. 9:52compared
  224. 9:53to this.
  225. 9:56So once again the reason well not once
  226. 9:59again but the reason we can do dot
  227. 10:01remotes instead of wait for child or
  228. 10:03find for child
  229. 10:05is because of the server. The server
  230. 10:09instantly loads everything in the game.
  231. 10:12So it instantly loads all of this
  232. 10:15uh all of this this everything. So
  233. 10:19because of that we can do remotes
  234. 10:20without airing.
  235. 10:22Now remotes attack onserver event which
  236. 10:27is a method and they even have open
  237. 10:29documentation for you but onserver event
  238. 10:34fires a script when fire server is
  239. 10:36called on the same remote event from a
  240. 10:39local script. I can't lie they did not
  241. 10:42have it before but that's really good.
  242. 10:44And it tells you what the parameters it
  243. 10:46is.
  244. 10:48So this these are automatically going to
  245. 10:50be present once you define the events or
  246. 10:53initiate it. So to answer event connect
  247. 10:58function remember muscle memory always
  248. 11:00connect function open
  249. 11:02parenthesis and you see that we have
  250. 11:05your little arguments in here. So
  251. 11:07player player because we want to be
  252. 11:10known as a player so we can access the
  253. 11:13um the the properties for it.
  254. 11:17Uh so yeah let's say
  255. 11:21this all right uh let's just add this
  256. 11:25back in another thing you see that we
  257. 11:28have something called tupole
  258. 11:30right anything after your initiation of
  259. 11:33the player you can add anything you want
  260. 11:36you can add test uh test arc test arc 2
  261. 11:40however this is frowned upon and most um
  262. 11:43old games do this for some reason but
  263. 11:46the meta is you want to have a table in
  264. 11:48here called argument data. This is
  265. 11:51anything after the player. So if we do
  266. 11:55that we can fire server.
  267. 11:58So a common mistake people make is that
  268. 12:00they say okay if the player is in here
  269. 12:02that means we have to do the player in
  270. 12:05here right? No the player is only a
  271. 12:09server thing right? It tells the server
  272. 12:10that which um client fires
  273. 12:13this. So we don't need to add player in
  274. 12:16here.
  275. 12:17But what we can add is add everything
  276. 12:19after the player which is argument data.
  277. 12:22So we can for example could be like
  278. 12:24holding space equals true, test one
  279. 12:26equals true, test two equals
  280. 12:29true.
  281. 12:31So but in this case we'll just make it
  282. 12:33an empty table for
  283. 12:35now. And there we go.
  284. 12:39So,
  285. 12:41we're going to check for the
  286. 12:43character local character equals player.
  287. 12:46character.
  288. 12:48The reason we do this is okay, what if
  289. 12:51the character is not there? That's going
  290. 12:52to be a problem. So, we're checking if
  291. 12:54there's a character. So, if character
  292. 12:58then then we can check for the humanoid,
  293. 13:02right? Cuz humanoid is always going to
  294. 13:05be there if a player is there. So, we
  295. 13:07want to make sure that the human is
  296. 13:08actually there and like someone didn't
  297. 13:09mess with it and destroy it or anything.
  298. 13:12Character find for child humanoid. All
  299. 13:14right.
  300. 13:17So, you'll see that um let's see, let's
  301. 13:19go over
  302. 13:21here. Humanoid.
  303. 13:25All right. You see all of these
  304. 13:26properties and etc for the humanoid,
  305. 13:28right?
  306. 13:30Typically, Roblox autofills it for you.
  307. 13:32But you see that it doesn't have all the
  308. 13:34functions for it like uh camera offset
  309. 13:37and stuff. So the way you can do that is
  310. 13:39through
  311. 13:40annotating. So we can two dots and you
  312. 13:43see that it automatically auto fills it
  313. 13:45for you. You can say
  314. 13:47humanoid. Now give the model. Yep. So
  315. 13:50humanoid like that. And now we can say
  316. 13:52humanoid at camera offset or anything we
  317. 13:54want. That's a property of the normal
  318. 13:56humanoid. But now once we do that we can
  319. 13:59say print
  320. 14:01player.name dot dot attack. So one thing
  321. 14:05I want to go through y'all with y'all is
  322. 14:08how concatenating works and how
  323. 14:10combining strings works especially in
  324. 14:12print
  325. 14:14statements. So in a print
  326. 14:16statement you can do print whatever you
  327. 14:19want. Add a comma tech test one test
  328. 14:23two. For every comma that's added, that
  329. 14:27means another space. So that's like
  330. 14:29saying
  331. 14:31attack space test one, space test two,
  332. 14:35right? So if we play the game and we
  333. 14:38hold, you'll see that. Okay, it's a
  334. 14:41comma after every single thing. So
  335. 14:44that's how one way of printing works
  336. 14:45through
  337. 14:46commas. Another way is through dot dot
  338. 14:49two dots.
  339. 14:51So you have to do make a new
  340. 14:54string. So dot dot doesn't automatically
  341. 14:57add a space between your um strings. So
  342. 15:00you have to add a space and then attack.
  343. 15:03Typically for me I like to do this just
  344. 15:05because I'm used to it. But comma is
  345. 15:08definitely more preferred throughout a
  346. 15:09lot of people. So up here we can say if
  347. 15:13humanoid then so we found the humanoid
  348. 15:16then we can say player name attack.
  349. 15:21So there we go.
  350. 15:23Attack. One major issue that you could
  351. 15:26see is it's spamming the server with
  352. 15:29attacks or attack prints and we don't
  353. 15:32want that. So one thing we can do is add
  354. 15:35a debounce or a
  355. 15:37buffer.
  356. 15:39So we can we can do that by saying if
  357. 15:43character find for child attacking. So,
  358. 15:47if the character finds um an instance
  359. 15:49called attacking, then we want to stop
  360. 15:51it from
  361. 15:52printing. Now, you may be wondering,
  362. 15:54okay, attacking, you're going to have to
  363. 15:56add something called attacking in the
  364. 15:58player for this to
  365. 15:59work. So, let's make a new instance
  366. 16:02called attacking equals instance new
  367. 16:06folder. You can this can be anything you
  368. 16:09want. This can be a bull value, an int
  369. 16:11value, a number value. It just it
  370. 16:13doesn't matter. In this case, I'm just
  371. 16:14going to do folder for just my
  372. 16:17preference. And now we can say uh let's
  373. 16:21go search instance new.
  374. 16:26Uh let's do instance. Here we
  375. 16:29go. There we go.
  376. 16:34Methods. Scroll through here. Scroll
  377. 16:36down a little bit. Here we
  378. 16:39go. Right here. Object replication.
  379. 16:43This is how you make new
  380. 16:45instances. So you see instance new part
  381. 16:48you parent it etc etc.
  382. 16:51So let's go back to
  383. 16:53here
  384. 16:55attacking.name. So we know that a
  385. 16:57property of a folder which you can find
  386. 16:59in the
  387. 17:01documentation. A property inherited from
  388. 17:04instance. So we go back to instance.
  389. 17:07Wait for it to load. You see that
  390. 17:09property of whatever is named.
  391. 17:13So we can call the folder attacking and
  392. 17:16we can parent the folder to the
  393. 17:17character which is what the script is
  394. 17:19looking for. Right?
  395. 17:21So the main thing people um need to wrap
  396. 17:25their head around is the difference
  397. 17:27between variable names and the actual
  398. 17:31name of the instance that they're
  399. 17:32creating. Right? So we can call this a
  400. 17:34as the uh brain route right here. This
  401. 17:38doesn't affect the name of this. Vice
  402. 17:40versa, if we call this blah blah blah,
  403. 17:44this script wouldn't work anymore
  404. 17:46because we're trying to find the
  405. 17:47instance called attacking, not blah blah
  406. 17:49blah. So, let's change back to
  407. 17:52attacking. And then let's play the game.
  408. 17:56You'll see you'll see one major issue
  409. 17:58with this. It doesn't work anymore after
  410. 18:00you attack once. See, the reason for
  411. 18:03this is we didn't destroy the attacking
  412. 18:05folder.
  413. 18:07So let's take a look at another service
  414. 18:09called debris service.
  415. 18:12Okay.
  416. 18:13Reload the page so it loads faster.
  417. 18:16So now we can go to methods. Once again
  418. 18:19remember methods have double dots,
  419. 18:21events have single dots.
  420. 18:23So we go to method add item. Once again
  421. 18:26basically what Adam does is that it
  422. 18:28destroys an instance after a certain
  423. 18:30amount of time and it tells you what the
  424. 18:32parameters are which is convenient too.
  425. 18:35So
  426. 18:38we can say
  427. 18:40well first off we have to make the
  428. 18:41service. So local debris equals game get
  429. 18:44service
  430. 18:46debris. Now we can say debris add item
  431. 18:51attacking which is your item instance
  432. 18:55comma let's say.5 seconds.
  433. 18:58Okay. Now this is going to add a buffer
  434. 19:01or cool down to how many times you can
  435. 19:03attack. So every.5 seconds you can
  436. 19:06attack again is what this is saying.
  437. 19:10Excuse me.
  438. 19:12Now if you hold left mouse button, you
  439. 19:14can see that it has a little buffer and
  440. 19:16it waits a little bit before you tech.
  441. 19:21Now that's good and all, but now let's
  442. 19:23go ahead and start with hitbox.
  443. 19:27Oh, also another thing, scoping a huge
  444. 19:30thing that you have to wrap your head
  445. 19:32around. How Roblox reads is from top to
  446. 19:37bottom. So one, two, three, four, five,
  447. 19:40six, seven, eight, nine, 10, all the way
  448. 19:42like that. It reads in a sequential
  449. 19:44order. So with that in mind, if we were
  450. 19:46to delete the debris add item, right,
  451. 19:48and put it up
  452. 19:50here, this would not work because the
  453. 19:54attacking instance hasn't been created
  454. 19:56yet according to the script. Even though
  455. 19:58if you look at it from face value,
  456. 19:59you'll see that it has been created, but
  457. 20:02Roblox reads from top to
  458. 20:05bottom. So you need to put this below
  459. 20:08the part where you instance the
  460. 20:10attacking
  461. 20:11folder like so.
  462. 20:14Now hit boxes.
  463. 20:19Let's go ahead and make a hitbox. And
  464. 20:21let me show you how the Robux
  465. 20:25uh part thing works.
  466. 20:28Let me add a new character.
  467. 20:32Like so. All right. This is our
  468. 20:33character that we can base the box from.
  469. 20:36Insert a part. Let me position the part
  470. 20:39to where the character
  471. 20:41is. There we go.
  472. 20:45Now, one major thing that you have to
  473. 20:47know is if you hold control and you
  474. 20:50expand or move your mouse back and
  475. 20:52forth, it expands on both axes.
  476. 20:56So let's say we want to go up a little
  477. 20:58bit. We want to go forward. I'm not
  478. 21:01holding control now. So if I hold this
  479. 21:03out, it's just going to move it like
  480. 21:04this. Rather, if I hold control now, I
  481. 21:07push this out, it's going to go both
  482. 21:09ways. But I want to move this out a
  483. 21:12little bit. I want it to be directly in
  484. 21:14front of the character. And I want it to
  485. 21:18expand out like
  486. 21:19so. Make it up like this. And we can
  487. 21:22call this the hitbox templates.
  488. 21:26Okay. Now
  489. 21:31an import an important thing you have to
  490. 21:33know for everything right is how these
  491. 21:35properties work. Can collide anchored
  492. 21:37and
  493. 21:38massless. If can collide is set to true
  494. 21:42then you can collide with it. If it's
  495. 21:43not then you can't. But in this case hit
  496. 21:45boxes we don't want it to collide with
  497. 21:47the character as in we don't want them
  498. 21:49to physically touch it and be bounced or
  499. 21:51a pulse back.
  500. 21:53So, we also want massless to be true.
  501. 21:56What massless does if it's false is that
  502. 21:58it adds sort of like a weight to the
  503. 22:00character. Basically, physics, right?
  504. 22:02Cuz you see over here you have a mass of
  505. 22:0554.62, whatever Robux units are. But if
  506. 22:09mass is set to false, then it's going to
  507. 22:12the part is going to add an extra type
  508. 22:14of mass to the character. We don't want
  509. 22:16that. We want the hitbox purely to be to
  510. 22:18be there just for hitbox detection.
  511. 22:21So, we turn these off. And up here,
  512. 22:24self-explanatory. You can change this to
  513. 22:2675. Transparency. Everyone in their mom
  514. 22:29should know what that means. And brick
  515. 22:31color.
  516. 22:33So, this is our little hit box. Like so.
  517. 22:36And we can drag this to replicate
  518. 22:39storage. Oops. There we go.
  519. 22:43So if I didn't mention this before, what
  520. 22:45replicated storage is and why it's so
  521. 22:47important is that everything that you
  522. 22:50want the both the server and client to
  523. 22:52see you put in replicated storage cuz
  524. 22:56the client can access anything
  525. 22:57replicated storage as seen here and same
  526. 23:00with the um server. So with that in
  527. 23:03mind, let's make a new variable called
  528. 23:06replicate storage assets.
  529. 23:09And now we can actually get the hitbox
  530. 23:10template from that.
  531. 23:14So we say local hitbox clone equals
  532. 23:20assets hitbox templates
  533. 23:23clone. So once again, if you don't know
  534. 23:26what clone does, we can go to the
  535. 23:28instance class like so. And now we can
  536. 23:32scroll down until we see clone, which
  537. 23:35should be right here.
  538. 23:37It tells you exactly what clone does.
  539. 23:40And now let's go back. We Let's call the
  540. 23:43hitbox clone. Let's name it, right?
  541. 23:45Hitbox.
  542. 23:46Hit box. Cuz we don't want to just call
  543. 23:48it template. That's kind of
  544. 23:50weird. And once again, name. That's how
  545. 23:53you know that's a valid
  546. 23:55property. Now, we can parent it to the
  547. 23:59workspace. There's already four in here
  548. 24:01from before, but let's print it to
  549. 24:03workspace boxes.
  550. 24:07Now, let me if y'all haven't seen
  551. 24:09welding in like the YouTube tutorials
  552. 24:11yet, I'm going to give you like a sort
  553. 24:13of brief run through what that is,
  554. 24:15right? So, local weld equals instance
  555. 24:19new weld. Now, we can say weld.part O.
  556. 24:24So, which is the first base part that
  557. 24:26the joint connects to. So, we want to
  558. 24:28weld the character's humanoid root
  559. 24:32part, right? So the character humanity
  560. 24:34part is this the thing that the player
  561. 24:37this updates every time the player
  562. 24:38moves. It essentially glues all of these
  563. 24:41parts
  564. 24:42together.
  565. 24:44Right.
  566. 24:47So let's get rid of that. We want to
  567. 24:50weld the character human part to the
  568. 24:54hitbox
  569. 24:55clone. Also we want to parent the weld.
  570. 24:58Always remember to parent cuz if you
  571. 25:00don't that it's not going to work. So
  572. 25:02there we go. And that should
  573. 25:05work. So let's do this. Oh shoot. Also,
  574. 25:10I forgot to destroy the hitbox. So we'll
  575. 25:14say debris add item hitbox clone come.5
  576. 25:17or no.35. We want a little sort of delay
  577. 25:21in
  578. 25:22between. So if we attack, you'll see
  579. 25:27that the hit box is in there.
  580. 25:32Yep. However, you see that it's not
  581. 25:34offseted
  582. 25:35correctly. That brings me to my second
  583. 25:37point, which is how to offset in Roblox.
  584. 25:40So, if we click on the human report,
  585. 25:42click on move, you can see sort of the
  586. 25:45axes of how the character
  587. 25:48moves. So, general rule of thumb is
  588. 25:50X-axis moves left to right, Y up and
  589. 25:53down, and Z forward and back.
  590. 25:57So, we can say well.co co let's see go
  591. 26:02down here the offset point so equals cf
  592. 26:06frame new 0 comma 0 because you see XY
  593. 26:10however we want the Z to be sort of in
  594. 26:12for in the front a little bit so I'm
  595. 26:14going to
  596. 26:16say3 play the game you see that the
  597. 26:20player the hit box is in front of the
  598. 26:21player a little bit like so
  599. 26:26so another thing we want to mention
  600. 26:30What I'm going to show you is what
  601. 26:32happens if King Cloud is on.
  602. 26:35Let me turn this off real quick and hit
  603. 26:37and go to the dummy.
  604. 26:40You'll see that there's no collision
  605. 26:42happening. However, if I go over here,
  606. 26:45turn this on
  607. 26:47and start walking up to the
  608. 26:49dummy. Yep, we do not want that. This is
  609. 26:52stupid and shouldn't be a thing. So,
  610. 26:56yeah, turn this off.
  611. 26:59Now the actual hitbox detecting
  612. 27:03uh let's go to uh let me see if I'm
  613. 27:06still recording. Yep.
  614. 27:09So we want to create a new
  615. 27:13thread, right?
  616. 27:15Threading. So let me go a brief overview
  617. 27:18of what task is and what threads
  618. 27:21are. Excuse me.
  619. 27:24So what thirding is is that it creates a
  620. 27:27sort of new parallel where different
  621. 27:29functions different scripts can run at
  622. 27:31simultaneously at the same time. So
  623. 27:34let's say this right we have two threads
  624. 27:37that means this runs in in a different
  625. 27:40parallel as this one. So if we were to
  626. 27:42say workspace wait for child which I
  627. 27:45mentioned before if we do this and it's
  628. 27:47not there it's going to yield right? So
  629. 27:49blah blah blah. But if from here we
  630. 27:50print this ignores the wait for
  631. 27:55child this is going to print anyways
  632. 27:57even though it should wait for this but
  633. 28:00because it's in a different thread or
  634. 28:02parallel it doesn't. So if we attack
  635. 28:07you'll see that this ignores wait for
  636. 28:08child. However wait you'll see that
  637. 28:11there is a infinite yield or infinite
  638. 28:14yield. This is because even though
  639. 28:18you've already made a new uh thread,
  640. 28:20errors can occur within that
  641. 28:23thread. This is important for
  642. 28:24understanding how memory leaks work and
  643. 28:26things like that because people usually
  644. 28:27just spam test at spawn if they like
  645. 28:31want things to run the same thing at
  646. 28:32once, but they don't disconnect
  647. 28:35functions. So, always always remember to
  648. 28:38disconnect your things and things like
  649. 28:39that. But knowing that, let's do the
  650. 28:43hitbox
  651. 28:44detection. So while true or while hitbox
  652. 28:49clone.parent do so what this is saying
  653. 28:53is while the hitbox is parented to
  654. 28:55workspace hitboxes we do. So testweight
  655. 29:01um another thing testweight you can read
  656. 29:03it uh don't use weight because uh it's
  657. 29:08separated. So
  658. 29:11we can do test.wait. So while the hitbox
  659. 29:13is actually there, we can do the
  660. 29:15detection.
  661. 29:19So let's go ahead and
  662. 29:22uh let's
  663. 29:23see look at the um documentation. So
  664. 29:27Roblox itself has sort of like a builtin
  665. 29:30hitbox sort of handler, right? So we can
  666. 29:33do world route which is just the whole
  667. 29:36game workspace. So we see something
  668. 29:39called get parts in part. Convenient,
  669. 29:42right? So
  670. 29:46we can say local parts found or parts
  671. 29:49collected for me I guess in part like
  672. 29:52that. And it's puts all of your little
  673. 29:56parameters that you want. So we want to
  674. 30:00detect it in the hitbox clone and you
  675. 30:02want prams. Even if you have no idea
  676. 30:05what the overlap params are, this tells
  677. 30:07you.
  678. 30:08So we need to find what overlap params
  679. 30:10are.
  680. 30:11Local params equals overlap params new.
  681. 30:15And you can read more about in the
  682. 30:17documentation, but in this case we just
  683. 30:19say prams.filter type
  684. 30:23exclude. And we want to we want the
  685. 30:25hitbox not to detect anything that has
  686. 30:28to do with the character or the actual
  687. 30:30hit boxes in the
  688. 30:32workspace. So we want to ignore that,
  689. 30:34but we wanted to collect everything
  690. 30:35else. So, we can say print parts
  691. 30:39collected. Oops. Like that.
  692. 30:43Um, let's see.
  693. 30:46Yeah, I'll explain the other thing
  694. 30:47later.
  695. 30:49However, now you can see that. Yep. It
  696. 30:52doesn't it doesn't find anything yet.
  697. 30:55However, if I go up here to the dummy, I
  698. 30:58hit it, there's something in there.
  699. 31:01So you'll see that everything in here is
  700. 31:05sort of a child within the character or
  701. 31:08the target that we're hitting. So right
  702. 31:10arm, right leg, right something like
  703. 31:13that. So you might be wondering how do
  704. 31:15we exactly get the the target right the
  705. 31:18actual model for the target. So in order
  706. 31:21to do that we can say first off we can
  707. 31:24uh start a loop. So underscore comma
  708. 31:28parts and part collects to do. So oh I
  709. 31:32forgot to explain this the um this sort
  710. 31:35of method right returns the returns a
  711. 31:38bunch of arrays. What arrays are is
  712. 31:41let's make a certain right here
  713. 31:44uh one test true false array one so like
  714. 31:50this we can say so array one corresponds
  715. 31:53to one array two corresponds to test
  716. 31:56three true four false that works so if
  717. 32:00we know that we can loop it like this so
  718. 32:04underscore the reason we do underscore
  719. 32:05is because we're not going to use the
  720. 32:07index for it The index is essentially
  721. 32:10one, two, three, and four. But we're
  722. 32:12just we're not going to worry about
  723. 32:13that. We're we're worrying about the
  724. 32:15values that are inside which are these.
  725. 32:19So we can
  726. 32:22say if
  727. 32:26parts. So if the part has a
  728. 32:30parent
  729. 32:32and we can find a humanoid in the parent
  730. 32:37then now we can say we can make a new
  731. 32:40variable called local target. You can
  732. 32:43call this whatever you want. The the
  733. 32:46thing you got to understand about Roblox
  734. 32:47is it's um very uh it's very free. You
  735. 32:52can do whatever you want with it.
  736. 32:55So knowing this we can just say local
  737. 32:58target hit say
  738. 32:59local or whatever you want but let's say
  739. 33:02target hit equals part.p parent which is
  740. 33:05the
  741. 33:07model and now we can say print target
  742. 33:13hit. So this is going to print the
  743. 33:16template R
  744. 33:20six. There we go. Like that. And you see
  745. 33:23there's a little pause between every M1,
  746. 33:26which is
  747. 33:27good.
  748. 33:28However, one thing that's going to be an
  749. 33:31issue is that the player is going to die
  750. 33:35immediately. So, let me show you why.
  751. 33:38So, first off, we want to get the
  752. 33:39humanoid local target humanoid equals
  753. 33:42target hit humanoid. The reason we can
  754. 33:44do humanoid instead of find for child,
  755. 33:46wait for child is because we already
  756. 33:48know the humanoid is there from this
  757. 33:52So we can do that and
  758. 33:55then we can say target humanoid. Let's
  759. 33:58go over here to our documentation
  760. 34:02and let's look
  761. 34:03at our
  762. 34:05humanoid. Go over here to
  763. 34:09methods take damage right here.
  764. 34:13So you can conveniently make the
  765. 34:16character take damage and of course
  766. 34:19everything protection like that. So
  767. 34:22we can say target humanoid take damage.
  768. 34:25You see that it doesn't autocomplete. So
  769. 34:27we can do that is through annotating. So
  770. 34:30the two dots and we can say that okay
  771. 34:32the target humanoid we know is a
  772. 34:34humanoid. So we can do that. Now it
  773. 34:37automp completes like
  774. 34:39so. Let's say make it take like five
  775. 34:41damage.
  776. 34:42or yeah, five damage is fine. So, if we
  777. 34:46play the
  778. 34:48game and we hit wait, let me make it
  779. 34:53actually show the health. So, we
  780. 34:55know viewer and health display always on
  781. 34:59like so.
  782. 35:01So, if we were to attack, you'll see
  783. 35:04that it dies right away, instantly,
  784. 35:06because there's no buffer between how
  785. 35:08many times you can hit the um target
  786. 35:12within a certain amount of time. So, to
  787. 35:14do that, we can make a new variable
  788. 35:18called local already hit. So, we're
  789. 35:20going to check if it's already been hit.
  790. 35:24Now we can say
  791. 35:30if already hits
  792. 35:33uh
  793. 35:34part.parent then return right. So,
  794. 35:42the reason we can't use target hit down
  795. 35:44here is through something called scoping
  796. 35:47and also how Roblox reads their um how
  797. 35:51Roblox how the Lua compiler reads code
  798. 35:53that you write. Remember, it reads it
  799. 35:55from up to down. So, every single line
  800. 35:57one by
  801. 35:58one. So, we know this now. So, we can't
  802. 36:02do target hit because it's just not
  803. 36:04defined yet. Even though we can see at
  804. 36:06face value, it's there. it's just not
  805. 36:07defined. So we can say part.parent or we
  806. 36:12can copy and paste this and move it down
  807. 36:14to where after you defined it and we can
  808. 36:17say target hit then return.
  809. 36:21So if we play the game, you'll see that
  810. 36:24there's going to be a big issue cuz it
  811. 36:26still dies instantly. That's because we
  812. 36:30didn't actually add the target to the
  813. 36:32table. So you can say already hit
  814. 36:38target hit is equal to true. And that's
  815. 36:41going to add a buffer to it. So you can
  816. 36:43only hit the same character once within
  817. 36:45every hit
  818. 36:46box. So if we walk up, we hit him. You
  819. 36:50see that he's being hit slowly and he's
  820. 36:52not being killed right away cuz for
  821. 36:54every hitbox uh instance it um it resets
  822. 36:58already hit.
  823. 37:00So, let's stop this. And that's pretty
  824. 37:05much
  825. 37:06uh how it's pretty much episode one for
  826. 37:09this tutorial.
  827. 37:12Um, a couple of takeaways that I want
  828. 37:14y'all to know is one, do not copy and
  829. 37:18paste. I I don't care if you say you're
  830. 37:19not copying and pasting. Do never copy
  831. 37:22and paste. You need to understand what
  832. 37:25exactly you're doing because that's the
  833. 37:27most important part. Copy and pasting.
  834. 37:28Sure, you can get that away in like
  835. 37:30Narbs and like that. Not when
  836. 37:32you're actually making a game. It's
  837. 37:34crucial that you know that. Also,
  838. 37:36scoping a big thing. Roblox reads things
  839. 37:40from up um from top to bottom. Let me
  840. 37:44give you another example. Scoping. Let's
  841. 37:46make a local function called test,
  842. 37:49right? And let's say local test variable
  843. 37:53equals
  844. 37:55fun. Scoping everything. What scoping
  845. 37:59says
  846. 38:00is this is a new scope. So if we were to
  847. 38:04say print test variable outside of this
  848. 38:06function, it wouldn't work cuz the
  849. 38:10script doesn't recognize the variable as
  850. 38:12a part of the rest of the um
  851. 38:15scope. So however, if you go in here and
  852. 38:19you type print test
  853. 38:20variable, there's no underline because
  854. 38:23it recognizes that test variable is in
  855. 38:25fact a variable in the function.
  856. 38:27So that's also important.
  857. 38:30And let's see what else. Um,
  858. 38:37uh, knowing it's really important that
  859. 38:40you know how to use documentation.
  860. 38:42Um, even even sometimes I use
  861. 38:45documentation just because I forget like
  862. 38:47what a method is or what it actually
  863. 38:48does. But just just read just read and
  864. 38:54you'll be able to understand way more
  865. 38:56and know how Roblox organization works
  866. 38:59and things like
  867. 39:00that. And that is pretty much
  868. 39:05it. Episode two, I'll probably get into
  869. 39:08how to play animations and sort of mini
  870. 39:11Roblox tutorials, but this is it pretty
  871. 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.