Humanoid (States, Properties, Methods) - Roblox Advanced Scripting #29 — Transcript
Full transcript
- 0:00you know back in the day with classic
- 0:02Roblox games that added zombies into
- 0:03their game this is kind of what the
- 0:05setup was like you had the zombie that
- 0:07would try to follow you and then you
- 0:09would have this zombie spawn location
- 0:11where you kill them and then they would
- 0:13respawn on top of the zombie spawner
- 0:15instantly but now that's come to make me
- 0:17realize that you can literally just
- 0:18spawn kill them and this is what a lot
- 0:21of classic Roblox games used to be like
- 0:23you could just easily spawn kill them
- 0:24like this and this has kind of made me
- 0:26realize that classic Roblox games
- 0:28definitely did not live up to its time
- 0:30like bro imagine if you're playing a
- 0:31game like this it's actually so easy
- 0:33like there is absolutely no challenge
- 0:35involves with this
- 0:37whatsoever wait wait wait whoa whoa whoa
- 0:40whoa where did these big green guys come
- 0:42from oh my
- 0:48God why why do I make these cringy
- 0:50intros bro all right let's think about
- 0:54this for a minute today's video is going
- 0:55to be about humanoids which are
- 0:57basically special objects in the game
- 0:59where you put them inside of a model and
- 1:01that model becomes a character or at
- 1:04least it gives the functionality of a
- 1:06character versus just a model full of
- 1:09parts now what do I mean by this well
- 1:11basically in any given Roblox game that
- 1:13has characters in them or have character
- 1:15functionalities like basically with what
- 1:17I'm doing here where I'm able to move
- 1:18around I'm able to jump I'm able to
- 1:20interact with the world as if I'm a
- 1:23character this is all because I have an
- 1:26object that's called a humanoid that is
- 1:28inside of my character model so if I go
- 1:32inside of the workspace and I go to my
- 1:34character then there's going to be an
- 1:37object here called a humanoid so this is
- 1:39what gives life to my character I guess
- 1:42if you want to call it that way and this
- 1:44can be said about basically any player
- 1:46or NPC that you see inside of the game
- 1:48like this zombie NPC over here if I were
- 1:50to just open him up then there's going
- 1:52to be a humanoid here and also this Noob
- 1:55right here if I open this up then
- 1:57there's going to be a humanoid object so
- 1:59this is what makes the difference
- 2:00between a model full of Parts versus a
- 2:04character so let me show you what this
- 2:05looks like if I actually delete this
- 2:07humanoid from this NPC so if I do that
- 2:10then there's a few noticeable
- 2:11differences first thing we don't see his
- 2:13name he also kind of like fell to the
- 2:15ground a little bit but he's not able to
- 2:16like move around at all like we
- 2:18basically got rid of the character
- 2:20functionality from this character so now
- 2:23this Noob is just a model that has a
- 2:27bunch of parts in it and that's all this
- 2:28is so once again this is what gives
- 2:31differentiation and humanoids are very
- 2:35complex or at least they can be very
- 2:36complex so there's going to be a lot of
- 2:38things to cover but for the sake of this
- 2:40episode what my goal here is to show you
- 2:44how we can Implement humanoids inside of
- 2:46our scripts how we can modify them and
- 2:49how we can use scripts to use humanoids
- 2:53to do whatever it is we want to do
- 2:55whether that's changing humanoid States
- 2:56whether that is taking damage for a
- 2:58player or any of those sorts of things I
- 3:00think it's important to know how to do
- 3:01this inside of your own scripts so
- 3:03that's going to be the goal for this
- 3:04episode uh so with that being said let's
- 3:07now go ahead and go straight into
- 3:08implementing now that we understand it
- 3:10let's Implement humanoids inside of
- 3:12Roblox studio so to start off with this
- 3:14video I'm going to show you a couple of
- 3:17very basic but also essential properties
- 3:19that we will use a lot with humanoids
- 3:21and I think you've already seen some of
- 3:23these properties that we've used
- 3:24throughout the entirety of this tutorial
- 3:26guide so I'm just going to hit play
- 3:27really quick and show you what these
- 3:28properties are so if I were to go into
- 3:30the workspace go and open up my
- 3:32character and we should have a humanoid
- 3:35uh inside of here so if we click this
- 3:37then there's going to be all of these
- 3:38properties that we can work with for
- 3:40this episode but some of the properties
- 3:42that are going to be very essential are
- 3:44the ones down here in the game category
- 3:47so one of them is Health obviously
- 3:49that's how much health you have in the
- 3:50game then you have things like walk
- 3:52speed which is how fast or how slow you
- 3:54can walk in the game and then you have
- 3:56jump power or jump height which is how
- 3:58high you can jump inside of the game so
- 4:00we can change these properties directly
- 4:03inside of our humanoid either using a
- 4:05script or just changing it right here
- 4:07like if I were to just go to test and
- 4:09then go to the server open up my
- 4:11character and go to the humanoid and
- 4:13then change let's say the walk speed to
- 4:1532 and then I decide to change the jump
- 4:17height to 15 and then if I were to let's
- 4:20say change the health so I have to
- 4:22change the max Health to 200 and then
- 4:24change the normal Health to 200 then
- 4:25that's what I would do I'll explain what
- 4:27this means in just a little bit but if I
- 4:28were to now go into the game then I am
- 4:31running a little bit faster and I'm also
- 4:33jumping a little bit faster because of
- 4:34that too so that's how we're able to
- 4:36change some of the properties here but
- 4:37now let me show you what we can do
- 4:39through a script example so I'm just
- 4:41going to hit stop and what I'm going to
- 4:42do is go to starter player and I'm going
- 4:45to insert a local script inside of
- 4:48starter character scripts so as you
- 4:50remember anything that's inside of
- 4:51starter character scripts is going to
- 4:53show up in our character in The
- 4:55workspace every single time our
- 4:57character loads into the game so what
- 4:59I'm going to do
- 5:00is Let's Make a system where if we press
- 5:02a certain key like R then it's going to
- 5:04add stats to our humanoid like our walk
- 5:08speed our jump power and our health so
- 5:09we can do that using user input service
- 5:11so what I'm going to do is say local
- 5:13user input service equals game colon get
- 5:17service user input service just like
- 5:19this and then I'm going to say user
- 5:20input service. input began colon connect
- 5:23function open and close parentheses
- 5:26input and then we're going to hit enter
- 5:27just like this so we're going to check
- 5:28what the key is we're going to say if
- 5:30input. keycode equals enum dokey code do
- 5:35let's say R then here's what we need to
- 5:38do now we need to First locate our
- 5:40character and then we're going to get
- 5:41our humanoid so what I'm going to do is
- 5:43say local character equals script.
- 5:47parent because as you remember anything
- 5:49inside of starter character scripts is
- 5:51going to be a child of our character
- 5:53model inside of the workspace so this is
- 5:56how we can locate our character and then
- 5:57we're going to locate the humanoid by
- 5:59saying local humanoid equals character
- 6:02colon weight for Child open and close
- 6:05parentheses humanoid just like this and
- 6:08so now what we're going to do is
- 6:10basically just change a bunch of
- 6:11properties here with the humanoid so
- 6:12we're going to say humanoid do walk
- 6:15speed just like this and I'm just going
- 6:17to take whatever the value currently is
- 6:19and add let's say 16 to it I'm going to
- 6:22drop a line and then say humanoid do
- 6:24jump power plus equals let's say 20 now
- 6:28here's one thing I want to add here for
- 6:30jump power so when we were playing the
- 6:32game there were two settings called jump
- 6:34power and um jump height I believe so if
- 6:37I go to humanoid show you jump height
- 6:40and jump power so we're not using jump
- 6:42power as like a a unit of metric we're
- 6:44using something called jump height and
- 6:46this is what it's set to by default but
- 6:48what I would actually say is we should
- 6:49use jump power because I think it's a
- 6:52more accurate measurement that aligns
- 6:54with something like walk speed and
- 6:56health and by default this is not true
- 6:58so this is a setting we have to
- 7:00configure so that we can have jump power
- 7:02and we do that through the games
- 7:03settings so if you have your Roblox game
- 7:05published then we can go to home and
- 7:07then go to game settings and then down
- 7:10here into world there's this jump
- 7:12setting here where by default it sets to
- 7:14jump height but we can actually check
- 7:16jump power which looks like this instead
- 7:18and by default it's around 50 if we
- 7:20round it down so now if we hit save then
- 7:23we can affect the jump power or the jump
- 7:26height using the jump power property I
- 7:28hope that makes sense so so now if we go
- 7:30into test and hit play then what we
- 7:32should see is if we hit R then it's
- 7:34going to increase our speed and also our
- 7:36jump power and if I do it again then
- 7:38it's going to make me go even faster and
- 7:40then just do it again and again and
- 7:41again and again and I'm just going to
- 7:43you know uh I can keep on going with
- 7:45this but I think you get the idea here
- 7:46now there's two properties for health
- 7:49one of them is Max health and one of
- 7:51them is normal health so the difference
- 7:53here between Max health and normal
- 7:55health is Max health is obviously how
- 7:58much health you can have in total and
- 8:01then health is what your health
- 8:03currently is because as you know Roblox
- 8:05has a system by default where it's like
- 8:07you increase health ever so slightly by
- 8:09the second or by the millisecond so if I
- 8:11were to let's say change my Max Health
- 8:13here to 200 then my health is going to
- 8:16stay at 100 because I have to update
- 8:19this health value to 200 as well now I'm
- 8:22in the client so I actually have to be
- 8:23in the server for this to be effective
- 8:25so if I go to the humanoid and change
- 8:28the max health to 200 then as you can
- 8:31see my health is slowly being
- 8:33incremented upward until it reaches 200
- 8:36for the max Health but I can just change
- 8:38this to 200 so that it's the max now if
- 8:40I were to try and change the health to
- 8:42something that's above the max like
- 8:44let's say 300 then by default it's just
- 8:46going to go to the maximum health that
- 8:49we are allowed for our character at this
- 8:51current moment so that's basically some
- 8:54properties that are pretty essential to
- 8:56humanoids but now we're going to cover
- 8:58some more things that you can do with
- 9:01scripting with humanoids the next thing
- 9:02I'm going to show you is humanoid States
- 9:04and this basically allows us to see how
- 9:07our humanoid is interacting with the
- 9:10world as we currently speak if we were
- 9:11to check up on it so some examples of
- 9:14humanoid states are things like walking
- 9:16or running and also things like jumping
- 9:19things like swimming climbing and all of
- 9:21those other sorts of things so we can do
- 9:23that through our script by detecting our
- 9:26state change in our humanoid so what I'm
- 9:28going to do is hit stop
- 9:30and I'm going to insert a new script
- 9:32just for the humanoid State changes uh
- 9:34so I'm just going to insert another
- 9:36local script inside of our starter
- 9:38character scripts and I'm going to
- 9:39rename this to State changed and then
- 9:42I'm going to rename our local script
- 9:44previously to change stats just like
- 9:47this and so now what I'm going to do
- 9:49with States changed is I'm basically
- 9:51just going to go to our previous script
- 9:52and I'm going to copy the same thing we
- 9:54had last time with character in humanoid
- 9:56and I'm going to paste it inside of here
- 9:57so now what we're going to do is say
- 9:59humanoid do state changed colon connect
- 10:05function open close parentheses enter
- 10:07now this takes in two parameters the
- 10:09first one being what was the state prior
- 10:12to the new state change so this is going
- 10:15to be called Old State just like this
- 10:18and the second parameter is going to be
- 10:19the new State of the State change so I'm
- 10:22going to call this one new state now if
- 10:24we were to just print this out so I can
- 10:26show you what this looks like so we can
- 10:27first print out Old State State and then
- 10:29we're going to separate this with a
- 10:31comma by saying New State just like that
- 10:33and now if we were to go into the game
- 10:35hit test and hit play then what we
- 10:36should see in the output is first thing
- 10:39on the left side it's going to be our
- 10:40old State and then what's on the right
- 10:42side is going to be our new state so
- 10:44right now our current state is running
- 10:47just like this and if we jump let's say
- 10:51then it's going to change a bunch of
- 10:52things so I'm going to do is uh clear
- 10:54the output here so I can show you what
- 10:55it looks like when we jump so if I jump
- 10:57then it first starts by going from
- 11:00running to Jumping then it went from
- 11:02jumping to freef falling so Free Falling
- 11:04means like you're falling down into the
- 11:05world and then we went from Free Falling
- 11:07to landing and then finally we went from
- 11:09Landing to running so all of these uh
- 11:12State changes happened within the span
- 11:14of like a second when we jump and then
- 11:16we like fall back to the ground to land
- 11:19and then go back to our running state so
- 11:21most of the time our our humanoids are
- 11:23going to be running they're going to be
- 11:25in the running state but like I
- 11:26mentioned there's other states like
- 11:28climbing and also swimming as well but
- 11:31those are going to be very uncommon
- 11:33compared to just running and all these
- 11:35other sorts of things so we can do some
- 11:37pretty cool things with these uh local
- 11:38scripts which I'm going to show you
- 11:40later in this episode but that's like
- 11:41kind of something I wanted to add there
- 11:43for humanoid State changes now we can
- 11:46detect what these states are to perform
- 11:49certain actions like let's say we are
- 11:52currently jumping then we want to add a
- 11:54double jump to whenever they decide to
- 11:57jump up again uh once again I'm going to
- 11:58show you how to do do this later but
- 12:00let's say we we had an example of
- 12:02basically checking what the new state is
- 12:04so we can say if new state equals and
- 12:07then as you notice down here with these
- 12:10humanoid State types this is an enum
- 12:12value which we can detect uh so we could
- 12:14say if new state equals enum Doh
- 12:17humanoid State type do let's say jumping
- 12:22then we can say print player is
- 12:28currently jumping just like this and
- 12:30then I'm also going to comment out our
- 12:32previous print statement like so so if
- 12:34we go into the game hit play then what
- 12:36we should see is every time we jump then
- 12:38it's going to say player is currently
- 12:39jumping and it's going to keep doing
- 12:41this every single time our player
- 12:43changes the state to be jumping for the
- 12:46new state not the old one so that's a
- 12:48little example that I wanted to give
- 12:50with humanoid States and I hope that you
- 12:51found this to be somewhat helpful now
- 12:53there are a bunch of methods that
- 12:56affects our humanoid in some way and I'm
- 12:58going to show you a few of them that you
- 13:00might find to be useful inside of your
- 13:01games the first one being take damage so
- 13:04basically what this does is it takes the
- 13:06humanoids health and then it reduces it
- 13:09by whatever we specify inside of the
- 13:11parameters for take damage so I think
- 13:13that part is pretty self-explanatory so
- 13:15if we were to let's say go to our change
- 13:17stat scripts that we created previously
- 13:19then what we can basically do is just
- 13:21say humanoid colon take damage just like
- 13:25this open and close parenthesis and we
- 13:27can specify how much health we want want
- 13:29to take for our humanoids so let's say
- 13:3110 every single time we do that now it's
- 13:33important to remember all humanoids
- 13:35start with 100 Health they start with 16
- 13:38walk speed and they also start with 50
- 13:40jump power so now let's see what happens
- 13:42if we hit R then it's going to take 10
- 13:45HP from our humanoid but it's slowly
- 13:48going to regenerate up again so it's at
- 13:5090 then if we do it again it's at 80 70
- 13:5360 50 40 30 20 10 and then we're dead
- 13:57now once again all of this is being done
- 13:59inside of the local side I don't really
- 14:01encourage you to try doing this on the
- 14:02local side you could do it on the server
- 14:04side um but this is just to demonstrate
- 14:06like as an example of how we would be
- 14:09changing our humanoid States you could
- 14:11even just like send this to the server
- 14:12as well just to handle making changes to
- 14:15our character as well but that is one
- 14:18method that I can show you which is take
- 14:20damage now another method that's pretty
- 14:22useful is the sit method which basically
- 14:25allows our character to sit forcefully
- 14:28on to a vehicle seat or a normal seat so
- 14:32basically what these seats look like is
- 14:34if I were to go into workspace and hit
- 14:35the plus sign and let's say we inserted
- 14:37a seat so this is what's called a seat
- 14:41object or a seat instance where when the
- 14:44player touches this part then the player
- 14:45sits on this part just like this we can
- 14:48forcefully make this happen through a
- 14:50script just by simply going to our
- 14:52scripts that we created let's locate our
- 14:56seat inside of the workspace so what I'm
- 14:57going to do is say local seat equals
- 15:00game. workpace colon wait for child seat
- 15:04just like this so we say seat colon sit
- 15:06open close parenthesis and then we pass
- 15:08in the humanoid just like this so this
- 15:10is how the sit method works okay so if
- 15:12we hit R then we should automatically be
- 15:15placed on the seat right over here so
- 15:17that is basically how we use this sit
- 15:20method so that's a little uh something
- 15:22that hopefully you'll find useful to be
- 15:24in your game as well not only does this
- 15:25work for seats but it also works for
- 15:27vehicle seats as well if you're trying
- 15:29to drive a vehicle and generally just
- 15:31for things like that now one more method
- 15:33that I'm going to show you that might be
- 15:34useful is the move two method which
- 15:37basically allows a character to move in
- 15:41a certain direction by walking towards
- 15:44it not necessarily teleport to it but
- 15:45walk towards it so this is how it's
- 15:47going to work let's say we had an NPC
- 15:50that's trying to walk towards a specific
- 15:52point or a position inside of the game
- 15:54we would do that by using this humanoid
- 15:56method called move to and there's
- 15:58actually move to methods but I will
- 16:00explain the second one in just a little
- 16:01bit so what we're going to do is I'm
- 16:03basically just going to go to view go to
- 16:04toolbox and we're going to find an NPC
- 16:07which actually there is one right here
- 16:09if I were to just click on this and
- 16:11insert this Noob inside of the game just
- 16:13like so we want this Noob to walk to a
- 16:17specific position inside of the game the
- 16:19way we can do that is let's say we
- 16:21inserted a part inside of the workspace
- 16:23like so so we're going to call this one
- 16:26point part just like that and then for
- 16:29our Noob what we're going to do is
- 16:30insert a script so I'm going to hit the
- 16:32plus sign insert a script just like this
- 16:34I'm first going to locate the character
- 16:36by saying local character equals script.
- 16:38parent and then we're going to say local
- 16:40humanoid equals character colon wait for
- 16:43child humanoid now in order to see this
- 16:46change what we're going to do is make a
- 16:49task. wa for let's say about 2 seconds
- 16:51at the very start of the script so next
- 16:54thing we're going to do is I'm I'm just
- 16:57going to make a print statement over
- 16:58here really quickly just to say move to
- 17:01the part just like this so we can see
- 17:03the change and then and then finally
- 17:05we're going to make reference to our
- 17:07Point part by saying local Point part
- 17:10equals game. workpace colon wait for
- 17:13child Point part just like this and so
- 17:15now what we're going to do is use our
- 17:17move two method by saying humanoid colon
- 17:21move 2 open and close parenthesis now we
- 17:24are going to pass in the position
- 17:26property of the point part and not the
- 17:29point part itself so we're going to say
- 17:31Point part. position just like this and
- 17:34so now if we go into the game and hit
- 17:37test and if we actually hit run then we
- 17:39should be able to see this after we wait
- 17:41about 2 seconds then as you can see the
- 17:43noob is going to attempt to move to this
- 17:47location right here now this isn't using
- 17:49something like pathfinding or anything
- 17:50like that this is a more basic way of
- 17:52just getting a character to move to a
- 17:54specific point I will talk about
- 17:56pathfinding in a future tutorial but um
- 17:58this is kind of like a basic way for a
- 18:00humanoid to be able to try and attempt
- 18:02to move to a park because if let's say
- 18:04there was a a huge wall that was
- 18:06blocking it like let's say it looked
- 18:08like this then this would actually
- 18:10prevent the character from moving to the
- 18:14part that it's supposed to go to so if
- 18:16we wait about 2 seconds here then it's
- 18:18going to I believe it's going to keep
- 18:20trying yeah it's going to keep trying
- 18:22until it moves to the position that it
- 18:24needs to go into well I'm just going oh
- 18:26wait no it looks like it stopped now
- 18:27okay so it it looks like it stopped
- 18:28stopped after trying for a bit I guess
- 18:30that's kind of just how it works I'm not
- 18:31really too sure but that is a method
- 18:33that you can use as well now there's two
- 18:36move to methods and it's actually
- 18:37important to understand the difference
- 18:39between the two so there's the humanoid
- 18:41move to Method but then there's the
- 18:44character move to method that basically
- 18:47teleports the player or the character to
- 18:50wherever the position is located so the
- 18:52difference here is if I were to com at
- 18:55this out and if I were to take the point
- 18:56par position and put it inside of here
- 18:58and if I were to go into the game and
- 19:01hit run just like this then after about
- 19:032 seconds what we should see is the noob
- 19:06got teleported to this part using the
- 19:09character move to the humanoid move to
- 19:12makes the character attempt to walk
- 19:14towards this part so there's a clear
- 19:17difference between the two and I want
- 19:18you to understand that character move to
- 19:21is not the same as humanoid move to so I
- 19:23think it's important to know when to use
- 19:26either of these move toos so that's kind
- 19:27of something I wanted to add here here
- 19:29and I hope you found these methods to be
- 19:30useful for humanoids when you're
- 19:32scripting them inside of your game so
- 19:33for this last part of the video we're
- 19:34going to make a double jump system
- 19:36inside of the game so basically if
- 19:38you're jumping and while you're in the
- 19:40air you can press space again to jump
- 19:43while you're in midair and that is
- 19:44what's called double jumping which is
- 19:46utilizing humanoid states to basically
- 19:49detect what state the character
- 19:51currently is in and how we can
- 19:52manipulate the states so that they can
- 19:55jump while they're in the air so that's
- 19:57what I'm going to be showing you how to
- 19:58do here here but before we do there's
- 19:59actually a couple of things I forgot to
- 20:01mention with States so if I hit stop and
- 20:04if I were to quickly go to our states
- 20:06change script there's two things we can
- 20:08do with our humanoids to first of all
- 20:10detect what our humanoid state currently
- 20:12is and second to forcefully change the
- 20:16state whenever we want inside of our
- 20:18script so if I were to let's say make a
- 20:20task. wait for about 3 seconds and if I
- 20:23were to let's say check on what the
- 20:26state currently is so if I were to say
- 20:28if humanoid colon get State open and
- 20:31close parentheses so this is the method
- 20:33that basically Returns what the current
- 20:36state of the humanoid is and then if I'm
- 20:38going to compare this to enum Doh
- 20:41humanoid State type do let's say running
- 20:45then we're going to force the player to
- 20:47jump upward so then what we're going to
- 20:48do is say humanoid colon change State
- 20:53just like this open and close
- 20:54parenthesis and then what we're going to
- 20:55pass in here is going to be the new
- 20:57humanoid State type so we're going to
- 20:59call this one jumping so now if we go
- 21:01into the game and hit play after we wait
- 21:03about 3 seconds so I I don't have my
- 21:05hands on the keyboard and as you just
- 21:07saw I jumped as a result of waiting for
- 21:103 seconds to see that my character was
- 21:12currently running and so that is
- 21:13essentially how we not only detect what
- 21:16the current state of the humanoid is but
- 21:18also how we can forcefully change the
- 21:19state so that's going to be important
- 21:20for when we create our double jumping
- 21:22script so now what I'm going to do is
- 21:24hit stop and we're now going to recreate
- 21:26our double jump script so what we're
- 21:28going to do is go to starter character
- 21:30scripts and we're going to insert a
- 21:32local script just like this and I'm
- 21:34going to rename this to double jump just
- 21:37like that um so there's a couple of
- 21:39things we need to make references to
- 21:41first thing is user input service so I'm
- 21:43going to say local user input service
- 21:46equals game get service user input
- 21:48service just like that and then I'm
- 21:49going to locate the character by saying
- 21:51local character equals script. parent
- 21:54and then the humanoid equals character
- 21:58waight child humanoid just like this now
- 22:02there's going to be two variables that
- 22:04we're going to use that are important
- 22:06the first one is going to be the time
- 22:09that elapsed since our last previous
- 22:12jump so that we can use that variable to
- 22:15calculate how long of a difference there
- 22:18was between the previous jump and when
- 22:20we currently jump I think this will make
- 22:22more sense once I actually show you this
- 22:24but basically what we're going to do is
- 22:25say local previous jump equals and we're
- 22:29going to set this to tick open and close
- 22:31parentheses just like this which
- 22:33basically Returns the number of seconds
- 22:34that have passed since the Unix Epoch
- 22:36time now if you remember from our Time
- 22:39episode I do not encourage you to use
- 22:40tick but just for the Simplicity of this
- 22:43script I'm going to show you tick first
- 22:46and I'm going to show you the method
- 22:47that I recommend so now next thing we're
- 22:49going to do is make a Boolean by
- 22:52basically determining whether the player
- 22:54currently is double jumping or not so
- 22:56we're going to say is double jump
- 22:58jumping equals false cuz that's what
- 23:00it's going to be by default so these are
- 23:02what we're going to be needing for the
- 23:04remainder of our script okay now we're
- 23:06going to add a humanoid do state changed
- 23:11event which gives us the old State and
- 23:13the new state so we're going to connect
- 23:16this with a function open close
- 23:18parentheses enter and we're going to
- 23:19pass in our old State and our new state
- 23:23like so so what we're going to do is
- 23:24check for our new state for two things
- 23:27first thing is our new state being if we
- 23:30landed on the ground so if new state
- 23:33equals enum Doh humanoid State type.
- 23:37landed so this is basically when the
- 23:39player touches the ground once they jump
- 23:41and then fall so if this happens then
- 23:43what we're going to do is set is double
- 23:46jumping uh equal to false because if we
- 23:50are let's say jumping and then we jump
- 23:52again for the double jump and then we
- 23:53finally land on the ground then that
- 23:55enables the player to double jump again
- 23:58so so that's why we have this here but
- 24:00next thing is detecting our new state if
- 24:03we are jumping so we're going to say
- 24:05else if new state equals enum Doh
- 24:10humanoid State type. jumping then so
- 24:13we're detecting if the player is jumping
- 24:15and if this does happen then we're going
- 24:18to set previous jump and it's going to
- 24:20be the current time that has elapsed
- 24:23since the Unix zoch time so if we were
- 24:25to let's say previous jump equals tick
- 24:28open and close parentheses and that's
- 24:29basically what this is we are resetting
- 24:31previous jump to be whatever the current
- 24:34new time that has elapsed since the Unix
- 24:36Epoch time is so this is our humanoid
- 24:39States state changed event that we have
- 24:42right here but now we need to add
- 24:44functionality to when we jump by using
- 24:47user input service so what we're going
- 24:48to do is say user input service. input
- 24:51begin colon connect function open close
- 24:53parentheses input just like this then
- 24:55we're going to hit enter so we're first
- 24:56going to check if input . keycode equals
- 25:00en. keycode dospace so if we're going to
- 25:03be jumping up and down then we're going
- 25:05to basically detect whether we are going
- 25:08to be double jumping or if we're going
- 25:09to be resetting any of our variables
- 25:12that we've had here okay now for this
- 25:13part we need to use our previous jump
- 25:16variable and also utilizing tick in
- 25:18general to figure out like when we're
- 25:21able to double jump given the time that
- 25:24we press space to enter into our new
- 25:27jump from the previous one so basically
- 25:29what I'm trying to explain here is being
- 25:31able to detect if the player pressed
- 25:35space quick enough to be able to do
- 25:37their double jump and so this is
- 25:39basically what it's going to look like
- 25:40so what we're going to do is make a
- 25:42conditional here by saying if tick open
- 25:44and close parenthesis so this is going
- 25:46to return the number of seconds that
- 25:48have passed since the Unix Epoch time
- 25:50and then we're going to subtract this
- 25:51with the previous jump duration that we
- 25:55specified up here at the very beginning
- 25:57and then we need to add in a buffer time
- 25:59here which is like a threshold to say
- 26:01like okay if the player jumped quick
- 26:03enough during this period then we're
- 26:05going to allow the player to double jump
- 26:07so in this case our buffer time can be
- 26:100.2 then we're going to hit enter just
- 26:12like this so to further explain what
- 26:15this does if we let's say had a
- 26:17ridiculously big number like this this
- 26:19is going to be the Unix Epoch time for
- 26:22our previous jump and so if I were to
- 26:24basically just copy this and do the same
- 26:25thing down here and let's say this was 6
- 26:29so this is Tick which is right here
- 26:32previous jump is this which is our
- 26:35previous time that we had over here if
- 26:37we subtracted these two it's an
- 26:39extremely marginal size difference like
- 26:41it's a very small difference but it's
- 26:43enough for us to determine if the player
- 26:45is eligible to double jump and I hope
- 26:46that this analogy has made you
- 26:48understand it a little bit more with
- 26:49like these comments that I had over here
- 26:51so now that we have that understanding
- 26:53we're first going to check if the
- 26:55humanoids state so we're going to get
- 26:57the state of the humanoid we're going to
- 26:59say if the humanoid state is equal to
- 27:01falling so humanoid State type. falling
- 27:05oh no free falling so Free Falling this
- 27:07is the the state that we're going to use
- 27:09so we're also going to say and not is
- 27:12double jumping then so basically what
- 27:15this conditional does is it checks if
- 27:17the player is currently falling after
- 27:19they jumped and if the player has not
- 27:22double jumped yet so then what we're
- 27:24going to do is say is double jumping
- 27:27equals true and then finally we're going
- 27:30to say humanoid colon change State open
- 27:34and close parentheses and then we're
- 27:35going to make the player jump again by
- 27:38putting in enum Doh humanoid State type.
- 27:42jumping just like that and we have our
- 27:45finished double jump script just like
- 27:47this so if we go into the game and hit
- 27:49play then what we should see is if we're
- 27:51in the game and we're just going to let
- 27:53one of our previous scripts just make us
- 27:55jump like this so I'm going to hit jump
- 27:57and it looks to working just fine but
- 27:59then if I double jump then it's going to
- 28:00work and and once we land on the ground
- 28:03that's when we're able to double jump
- 28:04again so I can't like spam the double
- 28:07jumping because it's only going to allow
- 28:08me to do it once and so this is
- 28:10basically how we use humanoid states to
- 28:13make a double jumping script and I hope
- 28:14you found this to be extremely helpful
- 28:16okay now before we end off this episode
- 28:18I did promise that I was going to show
- 28:20you the other way of utilizing time that
- 28:22doesn't require tick because tick is
- 28:24deprecated we're going to utilize date
- 28:26time for this so what I'm going to to do
- 28:28is replace tick with date time. now open
- 28:33and close parentheses and then we're
- 28:34going to get the Unix time stamp in
- 28:36milliseconds and we're going to divide
- 28:38that by a th just like this so any time
- 28:41that we've had tick we're just going to
- 28:42replace this with this calculation
- 28:44daytime. now. Unix time stamp in
- 28:46milliseconds divided by a th000 just
- 28:49like this now why is this calculation
- 28:52Like the Way It Is Well if we're trying
- 28:54to get the Unix time stamp in
- 28:56milliseconds this gives us a more
- 28:57accurate representation of how much time
- 29:00has passed since the Unix Epoch time
- 29:02because it's not going to give us a
- 29:03whole number like this it's actually
- 29:04going to give us like a more accurate
- 29:05number if we do it in milliseconds and
- 29:07if we divide this by a th then it's
- 29:09going to give us a accurate tick
- 29:12representation of how much time has
- 29:13passed in like let's say this decimal
- 29:16format right here rather than a whole
- 29:18number like this so when we do this
- 29:21calculation it basically does the exact
- 29:23same thing as we did with tick but
- 29:25instead it's more reliable and accurate
- 29:27because it's based on universal time
- 29:29rather than whatever the time zone is
- 29:31for that person again this all goes back
- 29:33to my Time episode but this is how you
- 29:37utilize the new way of time instead of
- 29:39using tick so that is basically going to
- 29:41be it for this episode if you're still
- 29:43confused about time you can go ahead and
- 29:45watch My Time episode that I will have
- 29:47for you right here to watch so go ahead
- 29:49and do that if you enjoyed it then be
- 29:50sure to leave a like And subscribe and I
- 29:53will see you in the next episode take
- 29:56care
About this transcript
This page contains the full transcript of Humanoid (States, Properties, Methods) - Roblox Advanced Scripting #29 by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 6,185 words across 812 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.