YouTube2Text

[Part3] Roblox Combat System for Beginners | State System & Blocking — Transcript

by Senko · 2,839 words · 469 segments · language en · Watch on YouTube

Full transcript

  1. 0:00All right. So today I'll be showing you
  2. 0:01how to make a state system and a
  3. 0:03blocking system. So essentially the
  4. 0:06state service does is that we can checks
  5. 0:08for states. We can remove and add states
  6. 0:11which is all handled in the states
  7. 0:12folder. And I'll show you how to make a
  8. 0:14status handler or state handler which
  9. 0:17checks if the players attacking,
  10. 0:18blocking or stunned in the future and
  11. 0:21sets their walk speed to things like
  12. 0:23zero or a slow rock speed. We also added
  13. 0:26a blocking system which only works if
  14. 0:28the player is actually holding out a
  15. 0:30weapon. So for example, let's say we are
  16. 0:33attacking. We can see the state folder
  17. 0:35adds in all of our states like
  18. 0:36attacking, no block, no jump. This
  19. 0:39player can't jump within this time
  20. 0:40frame. And we also add a blocking, which
  21. 0:43if you block, you can see the state gets
  22. 0:45added. But if you stop holding F, it
  23. 0:47gets removed. And if you unequip your
  24. 0:49tool, it also gets removed.
  25. 0:52And of course, you're not able to block
  26. 0:53while or you're not able to attack while
  27. 0:55you're blocking. And yeah, hope you
  28. 0:58enjoy the video. All right, so for
  29. 1:01episode three today, we're going to be
  30. 1:03doing state system and blocking. So,
  31. 1:08previously mentioned in the uh last
  32. 1:10video, essentially what the state system
  33. 1:12is going to be doing is it's going to
  34. 1:14check is going to be a folder inside our
  35. 1:16character called status. And any state
  36. 1:20or status is added to the player, say
  37. 1:22attacking, stunned, blocking is going to
  38. 1:24be added into here, which the input
  39. 1:27script can use to detect how fast we
  40. 1:29want the player to walk and things like
  41. 1:32that. So, let's add a folder in here
  42. 1:35called
  43. 1:36status. And then we want to add a module
  44. 1:38script
  45. 1:39in our systems folder that we made
  46. 1:42called state service.
  47. 1:48So let's start off by just
  48. 1:51redefining the local module. It's a
  49. 1:53service so we know what exactly it is.
  50. 1:56And then we want to say function service
  51. 1:59dot add
  52. 2:01state. So we want this add state to the
  53. 2:03character. So let's add the character.
  54. 2:07And then we want to do state name which
  55. 2:09is going to be a string.
  56. 2:12And we want to add any
  57. 2:16extra any extra values that we want
  58. 2:18here. So let's call this
  59. 2:21uh extra data or I'm going to make this
  60. 2:24simple. So we can call this just uh
  61. 2:27duration
  62. 2:29number. All right. So the most essential
  63. 2:33values that we need is the character and
  64. 2:34state name. So if we do if character and
  65. 2:37state name then duration is just going
  66. 2:40to be optional.
  67. 2:42So local new state instance new let's
  68. 2:45make it like a folder or something or a
  69. 2:48boolean value there. New state name
  70. 2:51equals state name new state. parent
  71. 2:54equals character status like
  72. 2:57so we don't know if the status is
  73. 2:59actually there or not. So we can do
  74. 3:01local status
  75. 3:02folder character find out
  76. 3:05status and then if not status folder
  77. 3:08then return end. Otherwise, we'll just
  78. 3:11parent it to the states folder like so.
  79. 3:14Now, the reason we didn't do if
  80. 3:16character and state name and duration is
  81. 3:17because this is optional. So, we can say
  82. 3:20if duration then so duration is not nil
  83. 3:24then we can say test. delay duration,
  84. 3:27function essentially the script waits
  85. 3:30the selected duration and then it
  86. 3:32destroys the state like
  87. 3:35so. Now, another thing we can do we also
  88. 3:37can return the new state. So any script
  89. 3:40that uses it will get the state as
  90. 3:43variable name if they so want to.
  91. 3:45Otherwise we can just return nil if none
  92. 3:47of this
  93. 3:48happens. And now we can say function
  94. 3:51service remove
  95. 3:54state character, state name
  96. 3:59string. We can say yep look folder like
  97. 4:03so. If not status
  98. 4:06folder then return end. Otherwise we can
  99. 4:09loop through the whole
  100. 4:11folder state and status folder get
  101. 4:14children
  102. 4:15do if state.name equals equals state
  103. 4:18name then state destroy like
  104. 4:22so. Now that's done we can get out of
  105. 4:26this script right here. We can go to our
  106. 4:30comment system or our fist module.
  107. 4:35Let's get rid of all these
  108. 4:37comments. Now we can actually call the
  109. 4:40state service like so. Local state
  110. 4:43service equals require script.p
  111. 4:46parent.parent.state service. The reason
  112. 4:48we do parent.parent is we need to go to
  113. 4:51this one and this parent and then we can
  114. 4:53go to the overall systems folder. State
  115. 4:57service. Now we'll notice on here that
  116. 4:59we added a state called attacking
  117. 5:01earlier. We can get rid of this and we
  118. 5:04can use our state
  119. 5:06service add state character,
  120. 5:10attacking and we can make the duration
  121. 5:12animation to play.length like
  122. 5:15so.
  123. 5:17Or we can actually reference new state
  124. 5:21like so which is what the return is
  125. 5:24which is what the return is
  126. 5:26for. And then we can do test delay
  127. 5:30whatever animation to play.length length
  128. 5:33and then destroy it like that. However,
  129. 5:35this other way is way more efficient.
  130. 5:38Single liner, we can remove this and
  131. 5:41remove
  132. 5:43this. And then as well, same with our
  133. 5:46actually we don't even need to do this
  134. 5:47for hitbox. This is uh
  135. 5:50different. There we
  136. 5:52go. And now if we play the game or we
  137. 5:56need to actually check for the state in
  138. 5:58here. So we can go over here to function
  139. 6:01service.check state
  140. 6:06character, let's do arguments or dot dot
  141. 6:09dot. Essentially what dot dot is is it's
  142. 6:12tupil which is spelled like
  143. 6:16this. So tupil essentially means that we
  144. 6:18can add any extra strings or data that
  145. 6:20we want in here. So for example, we can
  146. 6:22say service check state
  147. 6:24character, stun, comm, blocking, comma
  148. 6:27test like so.
  149. 6:29That's what that
  150. 6:31is. And then in order to actually check
  151. 6:33if um order to see what dot dot is, we
  152. 6:36can add we can make it into a table like
  153. 6:40so. And let's just copy and paste
  154. 6:44this. And then we can
  155. 6:47say states to check and then
  156. 6:52for underscore comma state
  157. 6:55name and states check do if status
  158. 6:59folder find first
  159. 7:00child state name and return true
  160. 7:03otherwise we can say return false like
  161. 7:05so that's how you check the states like
  162. 7:09that and we go back we can
  163. 7:12say if state
  164. 7:14service check state character comma
  165. 7:17attacking and return like
  166. 7:21so. And then of course we also have to
  167. 7:24do it in the core I believe. No we
  168. 7:26don't.
  169. 7:28Okay. And yeah that's the only place we
  170. 7:30need to do
  171. 7:31it. Now if we play the
  172. 7:35game we'll see that we have a folder in
  173. 7:38our character called
  174. 7:39status. Oops. What happened
  175. 7:43here? attempt index. No. Oh,
  176. 7:47whoops. We need to do new state instead
  177. 7:50of set name.
  178. 7:51Whoops. And then we
  179. 7:54can play the
  180. 7:56game. If we equip our tool and you see
  181. 8:00status, you see a new folder gets added
  182. 8:02to status every
  183. 8:04time. There we go. This is attacking and
  184. 8:07it works.
  185. 8:11Now, now that we've created our state
  186. 8:13system, we can work on blocking now. So,
  187. 8:15in here we can
  188. 8:18say if user input service is key down in
  189. 8:22my key code F then print start blocking
  190. 8:26like
  191. 8:30so. However, you notice a one glaring
  192. 8:33problem with
  193. 8:35this. If you open chat and let's say you
  194. 8:38type like f or something you can see
  195. 8:40that it still runs. So this means our
  196. 8:45run service is not good for
  197. 8:46this. So in here we can just make a
  198. 8:49value called local f key
  199. 8:52held or
  200. 8:54yeah f key held is equal to
  201. 8:57false use input
  202. 9:01service if process. So basically process
  203. 9:03is if it's typing then you return end.
  204. 9:07So yep. So you see over here game
  205. 9:09process event which is if you're typing
  206. 9:11and everything like that. So input combo
  207. 9:13process then return
  208. 9:15end otherwise we can check if they
  209. 9:18pressed on f key held equals
  210. 9:21true. So there we
  211. 9:24go. And then we can go over here to our
  212. 9:28loop.
  213. 9:30We can say
  214. 9:31if not user input service is key down
  215. 9:35ether my key code f then f keyh held
  216. 9:37equals
  217. 9:39false. Now we can do blocking down here.
  218. 9:42If f key held then prints blocking
  219. 9:47otherwise we this is yeah do that.
  220. 9:52Now, if we go over here, play the game,
  221. 9:56you can see that, okay, we're
  222. 10:00blocking. And then if we start typing or
  223. 10:03anything like that, you see that it
  224. 10:09stops. Or instead of doing that, we can
  225. 10:12just do get rid of
  226. 10:14this.put Input
  227. 10:16ended connect function input,
  228. 10:20processed. We don't need the processed
  229. 10:23here. If input keycode
  230. 10:26equals enum.keycodef, then f keyhold
  231. 10:30equals false.
  232. 10:34So play the
  233. 10:37game. We open up chat. We start typing.
  234. 10:41It doesn't work in this case. We'll just
  235. 10:44do it the other way. Remove these
  236. 10:47and keep that in there. There we
  237. 10:50go.
  238. 10:52Now we can make an event, a remote event
  239. 10:55in here called
  240. 10:57blocking or block. Now we can say remote
  241. 11:02stop.block fire
  242. 11:04server and we call this
  243. 11:08true. Else we can just uh make them stop
  244. 11:11blocking like so.
  245. 11:14Now, we don't want this to constantly
  246. 11:16fire every single time like they're not
  247. 11:19every single time they just stop holding
  248. 11:21F. So, in order to combat this, we can
  249. 11:24actually find the
  250. 11:27character. So, we can say local
  251. 11:30character equals
  252. 11:33script.parent.parent and then we can say
  253. 11:36local status folder equals character
  254. 11:39with the child
  255. 11:40status column left.
  256. 11:43And then now we can say if status folder
  257. 11:46find child or if not status
  258. 11:50folder find child
  259. 11:52blocking then we can make them block
  260. 11:54otherwise if we found it then we make it
  261. 11:56stop
  262. 11:57blocking like
  263. 12:00so. And then now we got our comma system
  264. 12:04remote stop block on
  265. 12:06event
  266. 12:08player player comma boolean which is our
  267. 12:11board
  268. 12:14value. Now of course we'll just copy and
  269. 12:17paste this and then we'll get rid
  270. 12:21of this. There we
  271. 12:24go. Okay. So we only want them able to
  272. 12:27block if they have a tool equipped.
  273. 12:31So we can
  274. 12:34say if not character find for shadow
  275. 12:38which is a
  276. 12:40tool then
  277. 12:43uh return. Oh yeah then make them stop
  278. 12:45blocking like
  279. 12:50so. And we want to return it because we
  280. 12:53don't want anything below here to
  281. 12:55run. We'll call this block. There we go.
  282. 12:59case
  283. 13:00sensitive and that should be
  284. 13:03good. And we can say if status for find
  285. 13:07blocking then block
  286. 13:11false. Oh, I don't know why I called it
  287. 13:13state service or stat service be
  288. 13:16state. There we go. And we'll go over
  289. 13:19here and change
  290. 13:22that. All right.
  291. 13:25And let's go back to
  292. 13:27our input. This is going to be the
  293. 13:29blocking code. And then we go to combat
  294. 13:33system. And we want them to block. So if
  295. 13:37boolean then
  296. 13:41block else stop blocking like
  297. 13:44so. However, we wanted to check if
  298. 13:46there's sun or not. So we will call
  299. 13:49state
  300. 13:51service local state service equals
  301. 13:54require script.p parent state service
  302. 13:58the script.p parent and state service
  303. 13:59like so. And we say if state
  304. 14:03service check state character, comma,
  305. 14:05let's say they're stunned. Let's say
  306. 14:09they're attacking. Then we don't allow
  307. 14:11them to
  308. 14:12block and then we
  309. 14:18return. Otherwise, we
  310. 14:21can make them actually
  311. 14:23no. If they want to block, then we can
  312. 14:27check for these. Otherwise, if they stop
  313. 14:29if they stop blocking the skin, it's
  314. 14:30going to be universally accepted. We
  315. 14:32don't need to worry about these uh stun
  316. 14:34and attacking over
  317. 14:36here. So, we can say site service remove
  318. 14:40state character come
  319. 14:43blocking and then over here we can also
  320. 14:46see if they're blocking then
  321. 14:48return and state service. state
  322. 14:51character or no add
  323. 14:55state character comma blocking and
  324. 14:58that's it. We don't want a duration
  325. 15:00because we don't want it to get
  326. 15:02destroyed. And over here we can say if
  327. 15:04state service check
  328. 15:06state or no we don't even need to do
  329. 15:08that. Remove state automatically just
  330. 15:10removes it if it's there or not. So yeah
  331. 15:13that's it.
  332. 15:15Now, if we go to fist, we want to make
  333. 15:17it actually detect if they're blocking,
  334. 15:19then we don't attack. So, we add
  335. 15:21blocking, then return end like
  336. 15:24so. So, while they're attacking, we also
  337. 15:27want to add a value called no block
  338. 15:30because we don't want the player to
  339. 15:31immediately block after like immediately
  340. 15:33after they're attacking.
  341. 15:36So we can make a state called state
  342. 15:39service to add state no
  343. 15:42block mission to play.length we can make
  344. 15:45like point one second after
  345. 15:48that. So now if we go to
  346. 15:52our comment system we add a state since
  347. 15:56we added no block we can also detect for
  348. 15:58it here and we return end like so.
  349. 16:03And over here now we can actually work
  350. 16:06on the um the
  351. 16:11states. So we can say test spawn
  352. 16:13function cuz we want to run in a
  353. 16:16different
  354. 16:19thread. Let's just keep it up here.
  355. 16:23State
  356. 16:24handler like
  357. 16:26so. So we can say local final walk
  358. 16:29speed. Oops.
  359. 16:33local final walk speed equals 16. Final
  360. 16:36jump power is equal to 50. These are
  361. 16:39just our default variables that we want.
  362. 16:42We say if status folder find for shout
  363. 16:45attacking then want to set the final
  364. 16:48walk speed to half of that or no we just
  365. 16:51want to set it to 10 is equal to 10
  366. 16:53final jump power equals
  367. 16:55zero. And then after that we can say if
  368. 16:59set is four to five for sh
  369. 17:01blocking then we want to set the final
  370. 17:03walk speed to like five or let's make it
  371. 17:07seven and then final jump power equals
  372. 17:11zero. So
  373. 17:13now over here we can
  374. 17:16say humanoid. Oh we have to actually get
  375. 17:18humanoid
  376. 17:23here. There we go. humanoid.w walk speed
  377. 17:27equals final walk speed. humanoid.jump
  378. 17:30power equals final jump power. So as
  379. 17:32mentioned in the previous video, this is
  380. 17:34for setting the walk speed of existing
  381. 17:38states. So if we have a state in here,
  382. 17:39we'll set the player's walk speed
  383. 17:41accordingly. And we also want them to
  384. 17:43prevent them from jumping. So
  385. 17:48if you can
  386. 17:50say over here make
  387. 17:55a actually no let's just go over
  388. 17:58here. If final jump power equals equals
  389. 18:01zero then we want to prevent the
  390. 18:02humanoid from jumping. Set state
  391. 18:05enabled jumping comma false like
  392. 18:10so. And then yeah otherwise we can just
  393. 18:13set it to enabled. So the player can
  394. 18:15jump
  395. 18:18normally. All right, there we go. So
  396. 18:20that's our blocking. So over here, if we
  397. 18:23go ahead and play, you'll see
  398. 18:27that the blocking status is added to the
  399. 18:30player. And while the player's blocking,
  400. 18:32you see that they're slowed and they
  401. 18:33can't jump. Or if you unblock, you can
  402. 18:36now jump. So let's say we start
  403. 18:39attacking. Now we can
  404. 18:44block. You see the blocking status does
  405. 18:46actually get
  406. 18:48added. So we want to add a little more
  407. 18:50leeway or a little longer for block. So
  408. 18:54no
  409. 18:55block.3 like
  410. 18:58so. And that
  411. 19:02should pretty much be
  412. 19:04it. Uh let me edit this part in at the
  413. 19:07end. But all right. So now that we done
  414. 19:10that, we can play the game and we'll see
  415. 19:12that the blocking actually
  416. 19:15works based on our code over
  417. 19:18here and the blocking that we made in
  418. 19:21our fist server, our comment server like
  419. 19:25so. So if we look in our status folder,
  420. 19:29we
  421. 19:32equipped, we
  422. 19:35block, you see that blocks. So if we
  423. 19:37unequipped our tool, we need to
  424. 19:40actually add that in. So if not
  425. 19:45character, there we go. All right. So
  426. 19:48let's go to our combat service and we'll
  427. 19:50check for
  428. 19:53this. We can we need to remove all of
  429. 19:58this. Like
  430. 20:00so. And let's go ahead and format our
  431. 20:03script.
  432. 20:06And then now we only want to check for
  433. 20:08the tool in the character or in the
  434. 20:10boolean equals true part. So call found
  435. 20:13tool equals character find which is a
  436. 20:16tool. If found tool and found tool get
  437. 20:19attributed tool loaded then we want to
  438. 20:25block. So there we
  439. 20:28go. And for another thing we can just
  440. 20:30check if it's actually weapon.
  441. 20:34So if cache modules
  442. 20:37oops if cache modules found toolname
  443. 20:41then we actually
  444. 20:42block like so. And that's how you fix
  445. 20:46that part. And if we play the game we
  446. 20:49will see
  447. 20:50that open our
  448. 20:55character and if we unequip your tool we
  449. 20:57stop blocking. And yeah, that's that.
  450. 21:01And you see that there's a little delay
  451. 21:04between our blocking now cuz we added
  452. 21:05that in the script. And that's pretty
  453. 21:07much
  454. 21:09it. Now,
  455. 21:12essentially what we did today was that
  456. 21:14we made a new state system, hence state
  457. 21:16service right here. A new blocking
  458. 21:20system, which you can easily edit by
  459. 21:22just adding states in called no block
  460. 21:24and things like that. if we don't want
  461. 21:26the player to block within a certain
  462. 21:27time frame.
  463. 21:29And we added a state updater which
  464. 21:33handles our walk speed and jumping and
  465. 21:34things like that which can be expanded
  466. 21:36on later if we add things like dashing,
  467. 21:38sprinting, and things like
  468. 21:40that. So yeah, thank you for watching
  469. 21:44episode three.

About this transcript

This page contains the full transcript of [Part3] Roblox Combat System for Beginners | State System & Blocking by Senko, generated from the public captions YouTube serves with the video. The transcript has 2,839 words across 469 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.