YouTube2Text

Humanoid (States, Properties, Methods) - Roblox Advanced Scripting #29 — Transcript

by BrawlDev · 6,185 words · 812 segments · language en · Watch on YouTube

Full transcript

  1. 0:00you know back in the day with classic
  2. 0:02Roblox games that added zombies into
  3. 0:03their game this is kind of what the
  4. 0:05setup was like you had the zombie that
  5. 0:07would try to follow you and then you
  6. 0:09would have this zombie spawn location
  7. 0:11where you kill them and then they would
  8. 0:13respawn on top of the zombie spawner
  9. 0:15instantly but now that's come to make me
  10. 0:17realize that you can literally just
  11. 0:18spawn kill them and this is what a lot
  12. 0:21of classic Roblox games used to be like
  13. 0:23you could just easily spawn kill them
  14. 0:24like this and this has kind of made me
  15. 0:26realize that classic Roblox games
  16. 0:28definitely did not live up to its time
  17. 0:30like bro imagine if you're playing a
  18. 0:31game like this it's actually so easy
  19. 0:33like there is absolutely no challenge
  20. 0:35involves with this
  21. 0:37whatsoever wait wait wait whoa whoa whoa
  22. 0:40whoa where did these big green guys come
  23. 0:42from oh my
  24. 0:48God why why do I make these cringy
  25. 0:50intros bro all right let's think about
  26. 0:54this for a minute today's video is going
  27. 0:55to be about humanoids which are
  28. 0:57basically special objects in the game
  29. 0:59where you put them inside of a model and
  30. 1:01that model becomes a character or at
  31. 1:04least it gives the functionality of a
  32. 1:06character versus just a model full of
  33. 1:09parts now what do I mean by this well
  34. 1:11basically in any given Roblox game that
  35. 1:13has characters in them or have character
  36. 1:15functionalities like basically with what
  37. 1:17I'm doing here where I'm able to move
  38. 1:18around I'm able to jump I'm able to
  39. 1:20interact with the world as if I'm a
  40. 1:23character this is all because I have an
  41. 1:26object that's called a humanoid that is
  42. 1:28inside of my character model so if I go
  43. 1:32inside of the workspace and I go to my
  44. 1:34character then there's going to be an
  45. 1:37object here called a humanoid so this is
  46. 1:39what gives life to my character I guess
  47. 1:42if you want to call it that way and this
  48. 1:44can be said about basically any player
  49. 1:46or NPC that you see inside of the game
  50. 1:48like this zombie NPC over here if I were
  51. 1:50to just open him up then there's going
  52. 1:52to be a humanoid here and also this Noob
  53. 1:55right here if I open this up then
  54. 1:57there's going to be a humanoid object so
  55. 1:59this is what makes the difference
  56. 2:00between a model full of Parts versus a
  57. 2:04character so let me show you what this
  58. 2:05looks like if I actually delete this
  59. 2:07humanoid from this NPC so if I do that
  60. 2:10then there's a few noticeable
  61. 2:11differences first thing we don't see his
  62. 2:13name he also kind of like fell to the
  63. 2:15ground a little bit but he's not able to
  64. 2:16like move around at all like we
  65. 2:18basically got rid of the character
  66. 2:20functionality from this character so now
  67. 2:23this Noob is just a model that has a
  68. 2:27bunch of parts in it and that's all this
  69. 2:28is so once again this is what gives
  70. 2:31differentiation and humanoids are very
  71. 2:35complex or at least they can be very
  72. 2:36complex so there's going to be a lot of
  73. 2:38things to cover but for the sake of this
  74. 2:40episode what my goal here is to show you
  75. 2:44how we can Implement humanoids inside of
  76. 2:46our scripts how we can modify them and
  77. 2:49how we can use scripts to use humanoids
  78. 2:53to do whatever it is we want to do
  79. 2:55whether that's changing humanoid States
  80. 2:56whether that is taking damage for a
  81. 2:58player or any of those sorts of things I
  82. 3:00think it's important to know how to do
  83. 3:01this inside of your own scripts so
  84. 3:03that's going to be the goal for this
  85. 3:04episode uh so with that being said let's
  86. 3:07now go ahead and go straight into
  87. 3:08implementing now that we understand it
  88. 3:10let's Implement humanoids inside of
  89. 3:12Roblox studio so to start off with this
  90. 3:14video I'm going to show you a couple of
  91. 3:17very basic but also essential properties
  92. 3:19that we will use a lot with humanoids
  93. 3:21and I think you've already seen some of
  94. 3:23these properties that we've used
  95. 3:24throughout the entirety of this tutorial
  96. 3:26guide so I'm just going to hit play
  97. 3:27really quick and show you what these
  98. 3:28properties are so if I were to go into
  99. 3:30the workspace go and open up my
  100. 3:32character and we should have a humanoid
  101. 3:35uh inside of here so if we click this
  102. 3:37then there's going to be all of these
  103. 3:38properties that we can work with for
  104. 3:40this episode but some of the properties
  105. 3:42that are going to be very essential are
  106. 3:44the ones down here in the game category
  107. 3:47so one of them is Health obviously
  108. 3:49that's how much health you have in the
  109. 3:50game then you have things like walk
  110. 3:52speed which is how fast or how slow you
  111. 3:54can walk in the game and then you have
  112. 3:56jump power or jump height which is how
  113. 3:58high you can jump inside of the game so
  114. 4:00we can change these properties directly
  115. 4:03inside of our humanoid either using a
  116. 4:05script or just changing it right here
  117. 4:07like if I were to just go to test and
  118. 4:09then go to the server open up my
  119. 4:11character and go to the humanoid and
  120. 4:13then change let's say the walk speed to
  121. 4:1532 and then I decide to change the jump
  122. 4:17height to 15 and then if I were to let's
  123. 4:20say change the health so I have to
  124. 4:22change the max Health to 200 and then
  125. 4:24change the normal Health to 200 then
  126. 4:25that's what I would do I'll explain what
  127. 4:27this means in just a little bit but if I
  128. 4:28were to now go into the game then I am
  129. 4:31running a little bit faster and I'm also
  130. 4:33jumping a little bit faster because of
  131. 4:34that too so that's how we're able to
  132. 4:36change some of the properties here but
  133. 4:37now let me show you what we can do
  134. 4:39through a script example so I'm just
  135. 4:41going to hit stop and what I'm going to
  136. 4:42do is go to starter player and I'm going
  137. 4:45to insert a local script inside of
  138. 4:48starter character scripts so as you
  139. 4:50remember anything that's inside of
  140. 4:51starter character scripts is going to
  141. 4:53show up in our character in The
  142. 4:55workspace every single time our
  143. 4:57character loads into the game so what
  144. 4:59I'm going to do
  145. 5:00is Let's Make a system where if we press
  146. 5:02a certain key like R then it's going to
  147. 5:04add stats to our humanoid like our walk
  148. 5:08speed our jump power and our health so
  149. 5:09we can do that using user input service
  150. 5:11so what I'm going to do is say local
  151. 5:13user input service equals game colon get
  152. 5:17service user input service just like
  153. 5:19this and then I'm going to say user
  154. 5:20input service. input began colon connect
  155. 5:23function open and close parentheses
  156. 5:26input and then we're going to hit enter
  157. 5:27just like this so we're going to check
  158. 5:28what the key is we're going to say if
  159. 5:30input. keycode equals enum dokey code do
  160. 5:35let's say R then here's what we need to
  161. 5:38do now we need to First locate our
  162. 5:40character and then we're going to get
  163. 5:41our humanoid so what I'm going to do is
  164. 5:43say local character equals script.
  165. 5:47parent because as you remember anything
  166. 5:49inside of starter character scripts is
  167. 5:51going to be a child of our character
  168. 5:53model inside of the workspace so this is
  169. 5:56how we can locate our character and then
  170. 5:57we're going to locate the humanoid by
  171. 5:59saying local humanoid equals character
  172. 6:02colon weight for Child open and close
  173. 6:05parentheses humanoid just like this and
  174. 6:08so now what we're going to do is
  175. 6:10basically just change a bunch of
  176. 6:11properties here with the humanoid so
  177. 6:12we're going to say humanoid do walk
  178. 6:15speed just like this and I'm just going
  179. 6:17to take whatever the value currently is
  180. 6:19and add let's say 16 to it I'm going to
  181. 6:22drop a line and then say humanoid do
  182. 6:24jump power plus equals let's say 20 now
  183. 6:28here's one thing I want to add here for
  184. 6:30jump power so when we were playing the
  185. 6:32game there were two settings called jump
  186. 6:34power and um jump height I believe so if
  187. 6:37I go to humanoid show you jump height
  188. 6:40and jump power so we're not using jump
  189. 6:42power as like a a unit of metric we're
  190. 6:44using something called jump height and
  191. 6:46this is what it's set to by default but
  192. 6:48what I would actually say is we should
  193. 6:49use jump power because I think it's a
  194. 6:52more accurate measurement that aligns
  195. 6:54with something like walk speed and
  196. 6:56health and by default this is not true
  197. 6:58so this is a setting we have to
  198. 7:00configure so that we can have jump power
  199. 7:02and we do that through the games
  200. 7:03settings so if you have your Roblox game
  201. 7:05published then we can go to home and
  202. 7:07then go to game settings and then down
  203. 7:10here into world there's this jump
  204. 7:12setting here where by default it sets to
  205. 7:14jump height but we can actually check
  206. 7:16jump power which looks like this instead
  207. 7:18and by default it's around 50 if we
  208. 7:20round it down so now if we hit save then
  209. 7:23we can affect the jump power or the jump
  210. 7:26height using the jump power property I
  211. 7:28hope that makes sense so so now if we go
  212. 7:30into test and hit play then what we
  213. 7:32should see is if we hit R then it's
  214. 7:34going to increase our speed and also our
  215. 7:36jump power and if I do it again then
  216. 7:38it's going to make me go even faster and
  217. 7:40then just do it again and again and
  218. 7:41again and again and I'm just going to
  219. 7:43you know uh I can keep on going with
  220. 7:45this but I think you get the idea here
  221. 7:46now there's two properties for health
  222. 7:49one of them is Max health and one of
  223. 7:51them is normal health so the difference
  224. 7:53here between Max health and normal
  225. 7:55health is Max health is obviously how
  226. 7:58much health you can have in total and
  227. 8:01then health is what your health
  228. 8:03currently is because as you know Roblox
  229. 8:05has a system by default where it's like
  230. 8:07you increase health ever so slightly by
  231. 8:09the second or by the millisecond so if I
  232. 8:11were to let's say change my Max Health
  233. 8:13here to 200 then my health is going to
  234. 8:16stay at 100 because I have to update
  235. 8:19this health value to 200 as well now I'm
  236. 8:22in the client so I actually have to be
  237. 8:23in the server for this to be effective
  238. 8:25so if I go to the humanoid and change
  239. 8:28the max health to 200 then as you can
  240. 8:31see my health is slowly being
  241. 8:33incremented upward until it reaches 200
  242. 8:36for the max Health but I can just change
  243. 8:38this to 200 so that it's the max now if
  244. 8:40I were to try and change the health to
  245. 8:42something that's above the max like
  246. 8:44let's say 300 then by default it's just
  247. 8:46going to go to the maximum health that
  248. 8:49we are allowed for our character at this
  249. 8:51current moment so that's basically some
  250. 8:54properties that are pretty essential to
  251. 8:56humanoids but now we're going to cover
  252. 8:58some more things that you can do with
  253. 9:01scripting with humanoids the next thing
  254. 9:02I'm going to show you is humanoid States
  255. 9:04and this basically allows us to see how
  256. 9:07our humanoid is interacting with the
  257. 9:10world as we currently speak if we were
  258. 9:11to check up on it so some examples of
  259. 9:14humanoid states are things like walking
  260. 9:16or running and also things like jumping
  261. 9:19things like swimming climbing and all of
  262. 9:21those other sorts of things so we can do
  263. 9:23that through our script by detecting our
  264. 9:26state change in our humanoid so what I'm
  265. 9:28going to do is hit stop
  266. 9:30and I'm going to insert a new script
  267. 9:32just for the humanoid State changes uh
  268. 9:34so I'm just going to insert another
  269. 9:36local script inside of our starter
  270. 9:38character scripts and I'm going to
  271. 9:39rename this to State changed and then
  272. 9:42I'm going to rename our local script
  273. 9:44previously to change stats just like
  274. 9:47this and so now what I'm going to do
  275. 9:49with States changed is I'm basically
  276. 9:51just going to go to our previous script
  277. 9:52and I'm going to copy the same thing we
  278. 9:54had last time with character in humanoid
  279. 9:56and I'm going to paste it inside of here
  280. 9:57so now what we're going to do is say
  281. 9:59humanoid do state changed colon connect
  282. 10:05function open close parentheses enter
  283. 10:07now this takes in two parameters the
  284. 10:09first one being what was the state prior
  285. 10:12to the new state change so this is going
  286. 10:15to be called Old State just like this
  287. 10:18and the second parameter is going to be
  288. 10:19the new State of the State change so I'm
  289. 10:22going to call this one new state now if
  290. 10:24we were to just print this out so I can
  291. 10:26show you what this looks like so we can
  292. 10:27first print out Old State State and then
  293. 10:29we're going to separate this with a
  294. 10:31comma by saying New State just like that
  295. 10:33and now if we were to go into the game
  296. 10:35hit test and hit play then what we
  297. 10:36should see in the output is first thing
  298. 10:39on the left side it's going to be our
  299. 10:40old State and then what's on the right
  300. 10:42side is going to be our new state so
  301. 10:44right now our current state is running
  302. 10:47just like this and if we jump let's say
  303. 10:51then it's going to change a bunch of
  304. 10:52things so I'm going to do is uh clear
  305. 10:54the output here so I can show you what
  306. 10:55it looks like when we jump so if I jump
  307. 10:57then it first starts by going from
  308. 11:00running to Jumping then it went from
  309. 11:02jumping to freef falling so Free Falling
  310. 11:04means like you're falling down into the
  311. 11:05world and then we went from Free Falling
  312. 11:07to landing and then finally we went from
  313. 11:09Landing to running so all of these uh
  314. 11:12State changes happened within the span
  315. 11:14of like a second when we jump and then
  316. 11:16we like fall back to the ground to land
  317. 11:19and then go back to our running state so
  318. 11:21most of the time our our humanoids are
  319. 11:23going to be running they're going to be
  320. 11:25in the running state but like I
  321. 11:26mentioned there's other states like
  322. 11:28climbing and also swimming as well but
  323. 11:31those are going to be very uncommon
  324. 11:33compared to just running and all these
  325. 11:35other sorts of things so we can do some
  326. 11:37pretty cool things with these uh local
  327. 11:38scripts which I'm going to show you
  328. 11:40later in this episode but that's like
  329. 11:41kind of something I wanted to add there
  330. 11:43for humanoid State changes now we can
  331. 11:46detect what these states are to perform
  332. 11:49certain actions like let's say we are
  333. 11:52currently jumping then we want to add a
  334. 11:54double jump to whenever they decide to
  335. 11:57jump up again uh once again I'm going to
  336. 11:58show you how to do do this later but
  337. 12:00let's say we we had an example of
  338. 12:02basically checking what the new state is
  339. 12:04so we can say if new state equals and
  340. 12:07then as you notice down here with these
  341. 12:10humanoid State types this is an enum
  342. 12:12value which we can detect uh so we could
  343. 12:14say if new state equals enum Doh
  344. 12:17humanoid State type do let's say jumping
  345. 12:22then we can say print player is
  346. 12:28currently jumping just like this and
  347. 12:30then I'm also going to comment out our
  348. 12:32previous print statement like so so if
  349. 12:34we go into the game hit play then what
  350. 12:36we should see is every time we jump then
  351. 12:38it's going to say player is currently
  352. 12:39jumping and it's going to keep doing
  353. 12:41this every single time our player
  354. 12:43changes the state to be jumping for the
  355. 12:46new state not the old one so that's a
  356. 12:48little example that I wanted to give
  357. 12:50with humanoid States and I hope that you
  358. 12:51found this to be somewhat helpful now
  359. 12:53there are a bunch of methods that
  360. 12:56affects our humanoid in some way and I'm
  361. 12:58going to show you a few of them that you
  362. 13:00might find to be useful inside of your
  363. 13:01games the first one being take damage so
  364. 13:04basically what this does is it takes the
  365. 13:06humanoids health and then it reduces it
  366. 13:09by whatever we specify inside of the
  367. 13:11parameters for take damage so I think
  368. 13:13that part is pretty self-explanatory so
  369. 13:15if we were to let's say go to our change
  370. 13:17stat scripts that we created previously
  371. 13:19then what we can basically do is just
  372. 13:21say humanoid colon take damage just like
  373. 13:25this open and close parenthesis and we
  374. 13:27can specify how much health we want want
  375. 13:29to take for our humanoids so let's say
  376. 13:3110 every single time we do that now it's
  377. 13:33important to remember all humanoids
  378. 13:35start with 100 Health they start with 16
  379. 13:38walk speed and they also start with 50
  380. 13:40jump power so now let's see what happens
  381. 13:42if we hit R then it's going to take 10
  382. 13:45HP from our humanoid but it's slowly
  383. 13:48going to regenerate up again so it's at
  384. 13:5090 then if we do it again it's at 80 70
  385. 13:5360 50 40 30 20 10 and then we're dead
  386. 13:57now once again all of this is being done
  387. 13:59inside of the local side I don't really
  388. 14:01encourage you to try doing this on the
  389. 14:02local side you could do it on the server
  390. 14:04side um but this is just to demonstrate
  391. 14:06like as an example of how we would be
  392. 14:09changing our humanoid States you could
  393. 14:11even just like send this to the server
  394. 14:12as well just to handle making changes to
  395. 14:15our character as well but that is one
  396. 14:18method that I can show you which is take
  397. 14:20damage now another method that's pretty
  398. 14:22useful is the sit method which basically
  399. 14:25allows our character to sit forcefully
  400. 14:28on to a vehicle seat or a normal seat so
  401. 14:32basically what these seats look like is
  402. 14:34if I were to go into workspace and hit
  403. 14:35the plus sign and let's say we inserted
  404. 14:37a seat so this is what's called a seat
  405. 14:41object or a seat instance where when the
  406. 14:44player touches this part then the player
  407. 14:45sits on this part just like this we can
  408. 14:48forcefully make this happen through a
  409. 14:50script just by simply going to our
  410. 14:52scripts that we created let's locate our
  411. 14:56seat inside of the workspace so what I'm
  412. 14:57going to do is say local seat equals
  413. 15:00game. workpace colon wait for child seat
  414. 15:04just like this so we say seat colon sit
  415. 15:06open close parenthesis and then we pass
  416. 15:08in the humanoid just like this so this
  417. 15:10is how the sit method works okay so if
  418. 15:12we hit R then we should automatically be
  419. 15:15placed on the seat right over here so
  420. 15:17that is basically how we use this sit
  421. 15:20method so that's a little uh something
  422. 15:22that hopefully you'll find useful to be
  423. 15:24in your game as well not only does this
  424. 15:25work for seats but it also works for
  425. 15:27vehicle seats as well if you're trying
  426. 15:29to drive a vehicle and generally just
  427. 15:31for things like that now one more method
  428. 15:33that I'm going to show you that might be
  429. 15:34useful is the move two method which
  430. 15:37basically allows a character to move in
  431. 15:41a certain direction by walking towards
  432. 15:44it not necessarily teleport to it but
  433. 15:45walk towards it so this is how it's
  434. 15:47going to work let's say we had an NPC
  435. 15:50that's trying to walk towards a specific
  436. 15:52point or a position inside of the game
  437. 15:54we would do that by using this humanoid
  438. 15:56method called move to and there's
  439. 15:58actually move to methods but I will
  440. 16:00explain the second one in just a little
  441. 16:01bit so what we're going to do is I'm
  442. 16:03basically just going to go to view go to
  443. 16:04toolbox and we're going to find an NPC
  444. 16:07which actually there is one right here
  445. 16:09if I were to just click on this and
  446. 16:11insert this Noob inside of the game just
  447. 16:13like so we want this Noob to walk to a
  448. 16:17specific position inside of the game the
  449. 16:19way we can do that is let's say we
  450. 16:21inserted a part inside of the workspace
  451. 16:23like so so we're going to call this one
  452. 16:26point part just like that and then for
  453. 16:29our Noob what we're going to do is
  454. 16:30insert a script so I'm going to hit the
  455. 16:32plus sign insert a script just like this
  456. 16:34I'm first going to locate the character
  457. 16:36by saying local character equals script.
  458. 16:38parent and then we're going to say local
  459. 16:40humanoid equals character colon wait for
  460. 16:43child humanoid now in order to see this
  461. 16:46change what we're going to do is make a
  462. 16:49task. wa for let's say about 2 seconds
  463. 16:51at the very start of the script so next
  464. 16:54thing we're going to do is I'm I'm just
  465. 16:57going to make a print statement over
  466. 16:58here really quickly just to say move to
  467. 17:01the part just like this so we can see
  468. 17:03the change and then and then finally
  469. 17:05we're going to make reference to our
  470. 17:07Point part by saying local Point part
  471. 17:10equals game. workpace colon wait for
  472. 17:13child Point part just like this and so
  473. 17:15now what we're going to do is use our
  474. 17:17move two method by saying humanoid colon
  475. 17:21move 2 open and close parenthesis now we
  476. 17:24are going to pass in the position
  477. 17:26property of the point part and not the
  478. 17:29point part itself so we're going to say
  479. 17:31Point part. position just like this and
  480. 17:34so now if we go into the game and hit
  481. 17:37test and if we actually hit run then we
  482. 17:39should be able to see this after we wait
  483. 17:41about 2 seconds then as you can see the
  484. 17:43noob is going to attempt to move to this
  485. 17:47location right here now this isn't using
  486. 17:49something like pathfinding or anything
  487. 17:50like that this is a more basic way of
  488. 17:52just getting a character to move to a
  489. 17:54specific point I will talk about
  490. 17:56pathfinding in a future tutorial but um
  491. 17:58this is kind of like a basic way for a
  492. 18:00humanoid to be able to try and attempt
  493. 18:02to move to a park because if let's say
  494. 18:04there was a a huge wall that was
  495. 18:06blocking it like let's say it looked
  496. 18:08like this then this would actually
  497. 18:10prevent the character from moving to the
  498. 18:14part that it's supposed to go to so if
  499. 18:16we wait about 2 seconds here then it's
  500. 18:18going to I believe it's going to keep
  501. 18:20trying yeah it's going to keep trying
  502. 18:22until it moves to the position that it
  503. 18:24needs to go into well I'm just going oh
  504. 18:26wait no it looks like it stopped now
  505. 18:27okay so it it looks like it stopped
  506. 18:28stopped after trying for a bit I guess
  507. 18:30that's kind of just how it works I'm not
  508. 18:31really too sure but that is a method
  509. 18:33that you can use as well now there's two
  510. 18:36move to methods and it's actually
  511. 18:37important to understand the difference
  512. 18:39between the two so there's the humanoid
  513. 18:41move to Method but then there's the
  514. 18:44character move to method that basically
  515. 18:47teleports the player or the character to
  516. 18:50wherever the position is located so the
  517. 18:52difference here is if I were to com at
  518. 18:55this out and if I were to take the point
  519. 18:56par position and put it inside of here
  520. 18:58and if I were to go into the game and
  521. 19:01hit run just like this then after about
  522. 19:032 seconds what we should see is the noob
  523. 19:06got teleported to this part using the
  524. 19:09character move to the humanoid move to
  525. 19:12makes the character attempt to walk
  526. 19:14towards this part so there's a clear
  527. 19:17difference between the two and I want
  528. 19:18you to understand that character move to
  529. 19:21is not the same as humanoid move to so I
  530. 19:23think it's important to know when to use
  531. 19:26either of these move toos so that's kind
  532. 19:27of something I wanted to add here here
  533. 19:29and I hope you found these methods to be
  534. 19:30useful for humanoids when you're
  535. 19:32scripting them inside of your game so
  536. 19:33for this last part of the video we're
  537. 19:34going to make a double jump system
  538. 19:36inside of the game so basically if
  539. 19:38you're jumping and while you're in the
  540. 19:40air you can press space again to jump
  541. 19:43while you're in midair and that is
  542. 19:44what's called double jumping which is
  543. 19:46utilizing humanoid states to basically
  544. 19:49detect what state the character
  545. 19:51currently is in and how we can
  546. 19:52manipulate the states so that they can
  547. 19:55jump while they're in the air so that's
  548. 19:57what I'm going to be showing you how to
  549. 19:58do here here but before we do there's
  550. 19:59actually a couple of things I forgot to
  551. 20:01mention with States so if I hit stop and
  552. 20:04if I were to quickly go to our states
  553. 20:06change script there's two things we can
  554. 20:08do with our humanoids to first of all
  555. 20:10detect what our humanoid state currently
  556. 20:12is and second to forcefully change the
  557. 20:16state whenever we want inside of our
  558. 20:18script so if I were to let's say make a
  559. 20:20task. wait for about 3 seconds and if I
  560. 20:23were to let's say check on what the
  561. 20:26state currently is so if I were to say
  562. 20:28if humanoid colon get State open and
  563. 20:31close parentheses so this is the method
  564. 20:33that basically Returns what the current
  565. 20:36state of the humanoid is and then if I'm
  566. 20:38going to compare this to enum Doh
  567. 20:41humanoid State type do let's say running
  568. 20:45then we're going to force the player to
  569. 20:47jump upward so then what we're going to
  570. 20:48do is say humanoid colon change State
  571. 20:53just like this open and close
  572. 20:54parenthesis and then what we're going to
  573. 20:55pass in here is going to be the new
  574. 20:57humanoid State type so we're going to
  575. 20:59call this one jumping so now if we go
  576. 21:01into the game and hit play after we wait
  577. 21:03about 3 seconds so I I don't have my
  578. 21:05hands on the keyboard and as you just
  579. 21:07saw I jumped as a result of waiting for
  580. 21:103 seconds to see that my character was
  581. 21:12currently running and so that is
  582. 21:13essentially how we not only detect what
  583. 21:16the current state of the humanoid is but
  584. 21:18also how we can forcefully change the
  585. 21:19state so that's going to be important
  586. 21:20for when we create our double jumping
  587. 21:22script so now what I'm going to do is
  588. 21:24hit stop and we're now going to recreate
  589. 21:26our double jump script so what we're
  590. 21:28going to do is go to starter character
  591. 21:30scripts and we're going to insert a
  592. 21:32local script just like this and I'm
  593. 21:34going to rename this to double jump just
  594. 21:37like that um so there's a couple of
  595. 21:39things we need to make references to
  596. 21:41first thing is user input service so I'm
  597. 21:43going to say local user input service
  598. 21:46equals game get service user input
  599. 21:48service just like that and then I'm
  600. 21:49going to locate the character by saying
  601. 21:51local character equals script. parent
  602. 21:54and then the humanoid equals character
  603. 21:58waight child humanoid just like this now
  604. 22:02there's going to be two variables that
  605. 22:04we're going to use that are important
  606. 22:06the first one is going to be the time
  607. 22:09that elapsed since our last previous
  608. 22:12jump so that we can use that variable to
  609. 22:15calculate how long of a difference there
  610. 22:18was between the previous jump and when
  611. 22:20we currently jump I think this will make
  612. 22:22more sense once I actually show you this
  613. 22:24but basically what we're going to do is
  614. 22:25say local previous jump equals and we're
  615. 22:29going to set this to tick open and close
  616. 22:31parentheses just like this which
  617. 22:33basically Returns the number of seconds
  618. 22:34that have passed since the Unix Epoch
  619. 22:36time now if you remember from our Time
  620. 22:39episode I do not encourage you to use
  621. 22:40tick but just for the Simplicity of this
  622. 22:43script I'm going to show you tick first
  623. 22:46and I'm going to show you the method
  624. 22:47that I recommend so now next thing we're
  625. 22:49going to do is make a Boolean by
  626. 22:52basically determining whether the player
  627. 22:54currently is double jumping or not so
  628. 22:56we're going to say is double jump
  629. 22:58jumping equals false cuz that's what
  630. 23:00it's going to be by default so these are
  631. 23:02what we're going to be needing for the
  632. 23:04remainder of our script okay now we're
  633. 23:06going to add a humanoid do state changed
  634. 23:11event which gives us the old State and
  635. 23:13the new state so we're going to connect
  636. 23:16this with a function open close
  637. 23:18parentheses enter and we're going to
  638. 23:19pass in our old State and our new state
  639. 23:23like so so what we're going to do is
  640. 23:24check for our new state for two things
  641. 23:27first thing is our new state being if we
  642. 23:30landed on the ground so if new state
  643. 23:33equals enum Doh humanoid State type.
  644. 23:37landed so this is basically when the
  645. 23:39player touches the ground once they jump
  646. 23:41and then fall so if this happens then
  647. 23:43what we're going to do is set is double
  648. 23:46jumping uh equal to false because if we
  649. 23:50are let's say jumping and then we jump
  650. 23:52again for the double jump and then we
  651. 23:53finally land on the ground then that
  652. 23:55enables the player to double jump again
  653. 23:58so so that's why we have this here but
  654. 24:00next thing is detecting our new state if
  655. 24:03we are jumping so we're going to say
  656. 24:05else if new state equals enum Doh
  657. 24:10humanoid State type. jumping then so
  658. 24:13we're detecting if the player is jumping
  659. 24:15and if this does happen then we're going
  660. 24:18to set previous jump and it's going to
  661. 24:20be the current time that has elapsed
  662. 24:23since the Unix zoch time so if we were
  663. 24:25to let's say previous jump equals tick
  664. 24:28open and close parentheses and that's
  665. 24:29basically what this is we are resetting
  666. 24:31previous jump to be whatever the current
  667. 24:34new time that has elapsed since the Unix
  668. 24:36Epoch time is so this is our humanoid
  669. 24:39States state changed event that we have
  670. 24:42right here but now we need to add
  671. 24:44functionality to when we jump by using
  672. 24:47user input service so what we're going
  673. 24:48to do is say user input service. input
  674. 24:51begin colon connect function open close
  675. 24:53parentheses input just like this then
  676. 24:55we're going to hit enter so we're first
  677. 24:56going to check if input . keycode equals
  678. 25:00en. keycode dospace so if we're going to
  679. 25:03be jumping up and down then we're going
  680. 25:05to basically detect whether we are going
  681. 25:08to be double jumping or if we're going
  682. 25:09to be resetting any of our variables
  683. 25:12that we've had here okay now for this
  684. 25:13part we need to use our previous jump
  685. 25:16variable and also utilizing tick in
  686. 25:18general to figure out like when we're
  687. 25:21able to double jump given the time that
  688. 25:24we press space to enter into our new
  689. 25:27jump from the previous one so basically
  690. 25:29what I'm trying to explain here is being
  691. 25:31able to detect if the player pressed
  692. 25:35space quick enough to be able to do
  693. 25:37their double jump and so this is
  694. 25:39basically what it's going to look like
  695. 25:40so what we're going to do is make a
  696. 25:42conditional here by saying if tick open
  697. 25:44and close parenthesis so this is going
  698. 25:46to return the number of seconds that
  699. 25:48have passed since the Unix Epoch time
  700. 25:50and then we're going to subtract this
  701. 25:51with the previous jump duration that we
  702. 25:55specified up here at the very beginning
  703. 25:57and then we need to add in a buffer time
  704. 25:59here which is like a threshold to say
  705. 26:01like okay if the player jumped quick
  706. 26:03enough during this period then we're
  707. 26:05going to allow the player to double jump
  708. 26:07so in this case our buffer time can be
  709. 26:100.2 then we're going to hit enter just
  710. 26:12like this so to further explain what
  711. 26:15this does if we let's say had a
  712. 26:17ridiculously big number like this this
  713. 26:19is going to be the Unix Epoch time for
  714. 26:22our previous jump and so if I were to
  715. 26:24basically just copy this and do the same
  716. 26:25thing down here and let's say this was 6
  717. 26:29so this is Tick which is right here
  718. 26:32previous jump is this which is our
  719. 26:35previous time that we had over here if
  720. 26:37we subtracted these two it's an
  721. 26:39extremely marginal size difference like
  722. 26:41it's a very small difference but it's
  723. 26:43enough for us to determine if the player
  724. 26:45is eligible to double jump and I hope
  725. 26:46that this analogy has made you
  726. 26:48understand it a little bit more with
  727. 26:49like these comments that I had over here
  728. 26:51so now that we have that understanding
  729. 26:53we're first going to check if the
  730. 26:55humanoids state so we're going to get
  731. 26:57the state of the humanoid we're going to
  732. 26:59say if the humanoid state is equal to
  733. 27:01falling so humanoid State type. falling
  734. 27:05oh no free falling so Free Falling this
  735. 27:07is the the state that we're going to use
  736. 27:09so we're also going to say and not is
  737. 27:12double jumping then so basically what
  738. 27:15this conditional does is it checks if
  739. 27:17the player is currently falling after
  740. 27:19they jumped and if the player has not
  741. 27:22double jumped yet so then what we're
  742. 27:24going to do is say is double jumping
  743. 27:27equals true and then finally we're going
  744. 27:30to say humanoid colon change State open
  745. 27:34and close parentheses and then we're
  746. 27:35going to make the player jump again by
  747. 27:38putting in enum Doh humanoid State type.
  748. 27:42jumping just like that and we have our
  749. 27:45finished double jump script just like
  750. 27:47this so if we go into the game and hit
  751. 27:49play then what we should see is if we're
  752. 27:51in the game and we're just going to let
  753. 27:53one of our previous scripts just make us
  754. 27:55jump like this so I'm going to hit jump
  755. 27:57and it looks to working just fine but
  756. 27:59then if I double jump then it's going to
  757. 28:00work and and once we land on the ground
  758. 28:03that's when we're able to double jump
  759. 28:04again so I can't like spam the double
  760. 28:07jumping because it's only going to allow
  761. 28:08me to do it once and so this is
  762. 28:10basically how we use humanoid states to
  763. 28:13make a double jumping script and I hope
  764. 28:14you found this to be extremely helpful
  765. 28:16okay now before we end off this episode
  766. 28:18I did promise that I was going to show
  767. 28:20you the other way of utilizing time that
  768. 28:22doesn't require tick because tick is
  769. 28:24deprecated we're going to utilize date
  770. 28:26time for this so what I'm going to to do
  771. 28:28is replace tick with date time. now open
  772. 28:33and close parentheses and then we're
  773. 28:34going to get the Unix time stamp in
  774. 28:36milliseconds and we're going to divide
  775. 28:38that by a th just like this so any time
  776. 28:41that we've had tick we're just going to
  777. 28:42replace this with this calculation
  778. 28:44daytime. now. Unix time stamp in
  779. 28:46milliseconds divided by a th000 just
  780. 28:49like this now why is this calculation
  781. 28:52Like the Way It Is Well if we're trying
  782. 28:54to get the Unix time stamp in
  783. 28:56milliseconds this gives us a more
  784. 28:57accurate representation of how much time
  785. 29:00has passed since the Unix Epoch time
  786. 29:02because it's not going to give us a
  787. 29:03whole number like this it's actually
  788. 29:04going to give us like a more accurate
  789. 29:05number if we do it in milliseconds and
  790. 29:07if we divide this by a th then it's
  791. 29:09going to give us a accurate tick
  792. 29:12representation of how much time has
  793. 29:13passed in like let's say this decimal
  794. 29:16format right here rather than a whole
  795. 29:18number like this so when we do this
  796. 29:21calculation it basically does the exact
  797. 29:23same thing as we did with tick but
  798. 29:25instead it's more reliable and accurate
  799. 29:27because it's based on universal time
  800. 29:29rather than whatever the time zone is
  801. 29:31for that person again this all goes back
  802. 29:33to my Time episode but this is how you
  803. 29:37utilize the new way of time instead of
  804. 29:39using tick so that is basically going to
  805. 29:41be it for this episode if you're still
  806. 29:43confused about time you can go ahead and
  807. 29:45watch My Time episode that I will have
  808. 29:47for you right here to watch so go ahead
  809. 29:49and do that if you enjoyed it then be
  810. 29:50sure to leave a like And subscribe and I
  811. 29:53will see you in the next episode take
  812. 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.