[Part3] Roblox Combat System for Beginners | State System & Blocking — Transcript
Full transcript
- 0:00All right. So today I'll be showing you
- 0:01how to make a state system and a
- 0:03blocking system. So essentially the
- 0:06state service does is that we can checks
- 0:08for states. We can remove and add states
- 0:11which is all handled in the states
- 0:12folder. And I'll show you how to make a
- 0:14status handler or state handler which
- 0:17checks if the players attacking,
- 0:18blocking or stunned in the future and
- 0:21sets their walk speed to things like
- 0:23zero or a slow rock speed. We also added
- 0:26a blocking system which only works if
- 0:28the player is actually holding out a
- 0:30weapon. So for example, let's say we are
- 0:33attacking. We can see the state folder
- 0:35adds in all of our states like
- 0:36attacking, no block, no jump. This
- 0:39player can't jump within this time
- 0:40frame. And we also add a blocking, which
- 0:43if you block, you can see the state gets
- 0:45added. But if you stop holding F, it
- 0:47gets removed. And if you unequip your
- 0:49tool, it also gets removed.
- 0:52And of course, you're not able to block
- 0:53while or you're not able to attack while
- 0:55you're blocking. And yeah, hope you
- 0:58enjoy the video. All right, so for
- 1:01episode three today, we're going to be
- 1:03doing state system and blocking. So,
- 1:08previously mentioned in the uh last
- 1:10video, essentially what the state system
- 1:12is going to be doing is it's going to
- 1:14check is going to be a folder inside our
- 1:16character called status. And any state
- 1:20or status is added to the player, say
- 1:22attacking, stunned, blocking is going to
- 1:24be added into here, which the input
- 1:27script can use to detect how fast we
- 1:29want the player to walk and things like
- 1:32that. So, let's add a folder in here
- 1:35called
- 1:36status. And then we want to add a module
- 1:38script
- 1:39in our systems folder that we made
- 1:42called state service.
- 1:48So let's start off by just
- 1:51redefining the local module. It's a
- 1:53service so we know what exactly it is.
- 1:56And then we want to say function service
- 1:59dot add
- 2:01state. So we want this add state to the
- 2:03character. So let's add the character.
- 2:07And then we want to do state name which
- 2:09is going to be a string.
- 2:12And we want to add any
- 2:16extra any extra values that we want
- 2:18here. So let's call this
- 2:21uh extra data or I'm going to make this
- 2:24simple. So we can call this just uh
- 2:27duration
- 2:29number. All right. So the most essential
- 2:33values that we need is the character and
- 2:34state name. So if we do if character and
- 2:37state name then duration is just going
- 2:40to be optional.
- 2:42So local new state instance new let's
- 2:45make it like a folder or something or a
- 2:48boolean value there. New state name
- 2:51equals state name new state. parent
- 2:54equals character status like
- 2:57so we don't know if the status is
- 2:59actually there or not. So we can do
- 3:01local status
- 3:02folder character find out
- 3:05status and then if not status folder
- 3:08then return end. Otherwise, we'll just
- 3:11parent it to the states folder like so.
- 3:14Now, the reason we didn't do if
- 3:16character and state name and duration is
- 3:17because this is optional. So, we can say
- 3:20if duration then so duration is not nil
- 3:24then we can say test. delay duration,
- 3:27function essentially the script waits
- 3:30the selected duration and then it
- 3:32destroys the state like
- 3:35so. Now, another thing we can do we also
- 3:37can return the new state. So any script
- 3:40that uses it will get the state as
- 3:43variable name if they so want to.
- 3:45Otherwise we can just return nil if none
- 3:47of this
- 3:48happens. And now we can say function
- 3:51service remove
- 3:54state character, state name
- 3:59string. We can say yep look folder like
- 4:03so. If not status
- 4:06folder then return end. Otherwise we can
- 4:09loop through the whole
- 4:11folder state and status folder get
- 4:14children
- 4:15do if state.name equals equals state
- 4:18name then state destroy like
- 4:22so. Now that's done we can get out of
- 4:26this script right here. We can go to our
- 4:30comment system or our fist module.
- 4:35Let's get rid of all these
- 4:37comments. Now we can actually call the
- 4:40state service like so. Local state
- 4:43service equals require script.p
- 4:46parent.parent.state service. The reason
- 4:48we do parent.parent is we need to go to
- 4:51this one and this parent and then we can
- 4:53go to the overall systems folder. State
- 4:57service. Now we'll notice on here that
- 4:59we added a state called attacking
- 5:01earlier. We can get rid of this and we
- 5:04can use our state
- 5:06service add state character,
- 5:10attacking and we can make the duration
- 5:12animation to play.length like
- 5:15so.
- 5:17Or we can actually reference new state
- 5:21like so which is what the return is
- 5:24which is what the return is
- 5:26for. And then we can do test delay
- 5:30whatever animation to play.length length
- 5:33and then destroy it like that. However,
- 5:35this other way is way more efficient.
- 5:38Single liner, we can remove this and
- 5:41remove
- 5:43this. And then as well, same with our
- 5:46actually we don't even need to do this
- 5:47for hitbox. This is uh
- 5:50different. There we
- 5:52go. And now if we play the game or we
- 5:56need to actually check for the state in
- 5:58here. So we can go over here to function
- 6:01service.check state
- 6:06character, let's do arguments or dot dot
- 6:09dot. Essentially what dot dot is is it's
- 6:12tupil which is spelled like
- 6:16this. So tupil essentially means that we
- 6:18can add any extra strings or data that
- 6:20we want in here. So for example, we can
- 6:22say service check state
- 6:24character, stun, comm, blocking, comma
- 6:27test like so.
- 6:29That's what that
- 6:31is. And then in order to actually check
- 6:33if um order to see what dot dot is, we
- 6:36can add we can make it into a table like
- 6:40so. And let's just copy and paste
- 6:44this. And then we can
- 6:47say states to check and then
- 6:52for underscore comma state
- 6:55name and states check do if status
- 6:59folder find first
- 7:00child state name and return true
- 7:03otherwise we can say return false like
- 7:05so that's how you check the states like
- 7:09that and we go back we can
- 7:12say if state
- 7:14service check state character comma
- 7:17attacking and return like
- 7:21so. And then of course we also have to
- 7:24do it in the core I believe. No we
- 7:26don't.
- 7:28Okay. And yeah that's the only place we
- 7:30need to do
- 7:31it. Now if we play the
- 7:35game we'll see that we have a folder in
- 7:38our character called
- 7:39status. Oops. What happened
- 7:43here? attempt index. No. Oh,
- 7:47whoops. We need to do new state instead
- 7:50of set name.
- 7:51Whoops. And then we
- 7:54can play the
- 7:56game. If we equip our tool and you see
- 8:00status, you see a new folder gets added
- 8:02to status every
- 8:04time. There we go. This is attacking and
- 8:07it works.
- 8:11Now, now that we've created our state
- 8:13system, we can work on blocking now. So,
- 8:15in here we can
- 8:18say if user input service is key down in
- 8:22my key code F then print start blocking
- 8:26like
- 8:30so. However, you notice a one glaring
- 8:33problem with
- 8:35this. If you open chat and let's say you
- 8:38type like f or something you can see
- 8:40that it still runs. So this means our
- 8:45run service is not good for
- 8:46this. So in here we can just make a
- 8:49value called local f key
- 8:52held or
- 8:54yeah f key held is equal to
- 8:57false use input
- 9:01service if process. So basically process
- 9:03is if it's typing then you return end.
- 9:07So yep. So you see over here game
- 9:09process event which is if you're typing
- 9:11and everything like that. So input combo
- 9:13process then return
- 9:15end otherwise we can check if they
- 9:18pressed on f key held equals
- 9:21true. So there we
- 9:24go. And then we can go over here to our
- 9:28loop.
- 9:30We can say
- 9:31if not user input service is key down
- 9:35ether my key code f then f keyh held
- 9:37equals
- 9:39false. Now we can do blocking down here.
- 9:42If f key held then prints blocking
- 9:47otherwise we this is yeah do that.
- 9:52Now, if we go over here, play the game,
- 9:56you can see that, okay, we're
- 10:00blocking. And then if we start typing or
- 10:03anything like that, you see that it
- 10:09stops. Or instead of doing that, we can
- 10:12just do get rid of
- 10:14this.put Input
- 10:16ended connect function input,
- 10:20processed. We don't need the processed
- 10:23here. If input keycode
- 10:26equals enum.keycodef, then f keyhold
- 10:30equals false.
- 10:34So play the
- 10:37game. We open up chat. We start typing.
- 10:41It doesn't work in this case. We'll just
- 10:44do it the other way. Remove these
- 10:47and keep that in there. There we
- 10:50go.
- 10:52Now we can make an event, a remote event
- 10:55in here called
- 10:57blocking or block. Now we can say remote
- 11:02stop.block fire
- 11:04server and we call this
- 11:08true. Else we can just uh make them stop
- 11:11blocking like so.
- 11:14Now, we don't want this to constantly
- 11:16fire every single time like they're not
- 11:19every single time they just stop holding
- 11:21F. So, in order to combat this, we can
- 11:24actually find the
- 11:27character. So, we can say local
- 11:30character equals
- 11:33script.parent.parent and then we can say
- 11:36local status folder equals character
- 11:39with the child
- 11:40status column left.
- 11:43And then now we can say if status folder
- 11:46find child or if not status
- 11:50folder find child
- 11:52blocking then we can make them block
- 11:54otherwise if we found it then we make it
- 11:56stop
- 11:57blocking like
- 12:00so. And then now we got our comma system
- 12:04remote stop block on
- 12:06event
- 12:08player player comma boolean which is our
- 12:11board
- 12:14value. Now of course we'll just copy and
- 12:17paste this and then we'll get rid
- 12:21of this. There we
- 12:24go. Okay. So we only want them able to
- 12:27block if they have a tool equipped.
- 12:31So we can
- 12:34say if not character find for shadow
- 12:38which is a
- 12:40tool then
- 12:43uh return. Oh yeah then make them stop
- 12:45blocking like
- 12:50so. And we want to return it because we
- 12:53don't want anything below here to
- 12:55run. We'll call this block. There we go.
- 12:59case
- 13:00sensitive and that should be
- 13:03good. And we can say if status for find
- 13:07blocking then block
- 13:11false. Oh, I don't know why I called it
- 13:13state service or stat service be
- 13:16state. There we go. And we'll go over
- 13:19here and change
- 13:22that. All right.
- 13:25And let's go back to
- 13:27our input. This is going to be the
- 13:29blocking code. And then we go to combat
- 13:33system. And we want them to block. So if
- 13:37boolean then
- 13:41block else stop blocking like
- 13:44so. However, we wanted to check if
- 13:46there's sun or not. So we will call
- 13:49state
- 13:51service local state service equals
- 13:54require script.p parent state service
- 13:58the script.p parent and state service
- 13:59like so. And we say if state
- 14:03service check state character, comma,
- 14:05let's say they're stunned. Let's say
- 14:09they're attacking. Then we don't allow
- 14:11them to
- 14:12block and then we
- 14:18return. Otherwise, we
- 14:21can make them actually
- 14:23no. If they want to block, then we can
- 14:27check for these. Otherwise, if they stop
- 14:29if they stop blocking the skin, it's
- 14:30going to be universally accepted. We
- 14:32don't need to worry about these uh stun
- 14:34and attacking over
- 14:36here. So, we can say site service remove
- 14:40state character come
- 14:43blocking and then over here we can also
- 14:46see if they're blocking then
- 14:48return and state service. state
- 14:51character or no add
- 14:55state character comma blocking and
- 14:58that's it. We don't want a duration
- 15:00because we don't want it to get
- 15:02destroyed. And over here we can say if
- 15:04state service check
- 15:06state or no we don't even need to do
- 15:08that. Remove state automatically just
- 15:10removes it if it's there or not. So yeah
- 15:13that's it.
- 15:15Now, if we go to fist, we want to make
- 15:17it actually detect if they're blocking,
- 15:19then we don't attack. So, we add
- 15:21blocking, then return end like
- 15:24so. So, while they're attacking, we also
- 15:27want to add a value called no block
- 15:30because we don't want the player to
- 15:31immediately block after like immediately
- 15:33after they're attacking.
- 15:36So we can make a state called state
- 15:39service to add state no
- 15:42block mission to play.length we can make
- 15:45like point one second after
- 15:48that. So now if we go to
- 15:52our comment system we add a state since
- 15:56we added no block we can also detect for
- 15:58it here and we return end like so.
- 16:03And over here now we can actually work
- 16:06on the um the
- 16:11states. So we can say test spawn
- 16:13function cuz we want to run in a
- 16:16different
- 16:19thread. Let's just keep it up here.
- 16:23State
- 16:24handler like
- 16:26so. So we can say local final walk
- 16:29speed. Oops.
- 16:33local final walk speed equals 16. Final
- 16:36jump power is equal to 50. These are
- 16:39just our default variables that we want.
- 16:42We say if status folder find for shout
- 16:45attacking then want to set the final
- 16:48walk speed to half of that or no we just
- 16:51want to set it to 10 is equal to 10
- 16:53final jump power equals
- 16:55zero. And then after that we can say if
- 16:59set is four to five for sh
- 17:01blocking then we want to set the final
- 17:03walk speed to like five or let's make it
- 17:07seven and then final jump power equals
- 17:11zero. So
- 17:13now over here we can
- 17:16say humanoid. Oh we have to actually get
- 17:18humanoid
- 17:23here. There we go. humanoid.w walk speed
- 17:27equals final walk speed. humanoid.jump
- 17:30power equals final jump power. So as
- 17:32mentioned in the previous video, this is
- 17:34for setting the walk speed of existing
- 17:38states. So if we have a state in here,
- 17:39we'll set the player's walk speed
- 17:41accordingly. And we also want them to
- 17:43prevent them from jumping. So
- 17:48if you can
- 17:50say over here make
- 17:55a actually no let's just go over
- 17:58here. If final jump power equals equals
- 18:01zero then we want to prevent the
- 18:02humanoid from jumping. Set state
- 18:05enabled jumping comma false like
- 18:10so. And then yeah otherwise we can just
- 18:13set it to enabled. So the player can
- 18:15jump
- 18:18normally. All right, there we go. So
- 18:20that's our blocking. So over here, if we
- 18:23go ahead and play, you'll see
- 18:27that the blocking status is added to the
- 18:30player. And while the player's blocking,
- 18:32you see that they're slowed and they
- 18:33can't jump. Or if you unblock, you can
- 18:36now jump. So let's say we start
- 18:39attacking. Now we can
- 18:44block. You see the blocking status does
- 18:46actually get
- 18:48added. So we want to add a little more
- 18:50leeway or a little longer for block. So
- 18:54no
- 18:55block.3 like
- 18:58so. And that
- 19:02should pretty much be
- 19:04it. Uh let me edit this part in at the
- 19:07end. But all right. So now that we done
- 19:10that, we can play the game and we'll see
- 19:12that the blocking actually
- 19:15works based on our code over
- 19:18here and the blocking that we made in
- 19:21our fist server, our comment server like
- 19:25so. So if we look in our status folder,
- 19:29we
- 19:32equipped, we
- 19:35block, you see that blocks. So if we
- 19:37unequipped our tool, we need to
- 19:40actually add that in. So if not
- 19:45character, there we go. All right. So
- 19:48let's go to our combat service and we'll
- 19:50check for
- 19:53this. We can we need to remove all of
- 19:58this. Like
- 20:00so. And let's go ahead and format our
- 20:03script.
- 20:06And then now we only want to check for
- 20:08the tool in the character or in the
- 20:10boolean equals true part. So call found
- 20:13tool equals character find which is a
- 20:16tool. If found tool and found tool get
- 20:19attributed tool loaded then we want to
- 20:25block. So there we
- 20:28go. And for another thing we can just
- 20:30check if it's actually weapon.
- 20:34So if cache modules
- 20:37oops if cache modules found toolname
- 20:41then we actually
- 20:42block like so. And that's how you fix
- 20:46that part. And if we play the game we
- 20:49will see
- 20:50that open our
- 20:55character and if we unequip your tool we
- 20:57stop blocking. And yeah, that's that.
- 21:01And you see that there's a little delay
- 21:04between our blocking now cuz we added
- 21:05that in the script. And that's pretty
- 21:07much
- 21:09it. Now,
- 21:12essentially what we did today was that
- 21:14we made a new state system, hence state
- 21:16service right here. A new blocking
- 21:20system, which you can easily edit by
- 21:22just adding states in called no block
- 21:24and things like that. if we don't want
- 21:26the player to block within a certain
- 21:27time frame.
- 21:29And we added a state updater which
- 21:33handles our walk speed and jumping and
- 21:34things like that which can be expanded
- 21:36on later if we add things like dashing,
- 21:38sprinting, and things like
- 21:40that. So yeah, thank you for watching
- 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.