YouTube2Text

Haptic Service (Controller Vibration) - Roblox Advanced Scripting #33 (2025) — Transcript

by BrawlDev · 4,907 words · 705 segments · language en · Watch on YouTube

Full transcript

  1. 0:00Thanks for stopping by everyone. I'm
  2. 0:01inside of Mike's Motors because I'm
  3. 0:03trying to get myself a good car. Now, in
  4. 0:05order to determine what the best car is
  5. 0:08that Mike has to offer here, let's just
  6. 0:10look at the finer details of this one.
  7. 0:12This car's made looks to be out of
  8. 0:15cobblestone, which I thought cars are
  9. 0:17made out of metal, not cobblestone, so
  10. 0:19this is a little strange and it looks
  11. 0:21kind of ugly in my opinion. But, this
  12. 0:23one Oh my god, this looks so good. I
  13. 0:27might actually get this car. It looks
  14. 0:28very nice. It looks very nice. All
  15. 0:30right, Mike, I think I've come to a
  16. 0:32decision. I want to buy this red car
  17. 0:34right here.
  18. 0:35I have some Robux for you.
  19. 0:37Hopefully this is going to be enough to
  20. 0:38cover for the car. So, I'm just going to
  21. 0:39drop this and Okay, well, it's kind of
  22. 0:42on the ground, but I mean it's yours
  23. 0:43now.
  24. 0:44And I'm guessing these are the keys to
  25. 0:46the car, so I'm just going to swipe
  26. 0:48these. All right, looks very nice. Looks
  27. 0:50very nice. All right, I'm about to give
  28. 0:52this car a spin and I'm going to whip
  29. 0:53out my controller so I can really feel
  30. 0:55the rumble. All right, let's go in.
  31. 0:58Oh yeah. Wait, what happened to my What
  32. 1:01happened to my hat? Where did it go?
  33. 1:03That's a little whack, bro. All right,
  34. 1:06let's just drive on out of here. Oh
  35. 1:09yeah. Oh yeah. Oh yeah. This car is so
  36. 1:13nice. This car is so nice. I feel the
  37. 1:14rumble, too. Like I feel the rumble in
  38. 1:16my controller, too. Feels really good.
  39. 1:18Feels really good. But, oh wait, this
  40. 1:20this car feels a little unstable though.
  41. 1:23It's like if I if I try to move for a
  42. 1:25long period of time, it just kind of
  43. 1:26like rattles in here. Uh maybe I should
  44. 1:29be concerned about this. I have no idea.
  45. 1:32Uh
  46. 1:33Okay, wait, this car does not feel
  47. 1:35right. This car does not feel right in
  48. 1:37the slightest. I feel like something's
  49. 1:38about to break.
  50. 1:40Wait, what?
  51. 1:42Wait, my car just exploded.
  52. 1:45Bro, I got I got scammed, bro.
  53. 1:49What?
  54. 1:50All right, let's think about this for a
  55. 1:51minute. This video's going to be about
  56. 1:53haptic service, which is a a that allows
  57. 1:56us to add rumbling and vibrations to our
  58. 2:00controllers and to our mobile devices
  59. 2:02whenever we're playing a Roblox game.
  60. 2:04So, right now, I have my controller
  61. 2:06connected to this game, so I'm able to
  62. 2:08play this game with my controller. And
  63. 2:10while my controller is connected, I can
  64. 2:12get haptic feedback responses
  65. 2:15for whatever I decide to add
  66. 2:17with those things inside of the game.
  67. 2:19So, some examples that I've made involve
  68. 2:21jumping and then it provides a haptic
  69. 2:24feedback on my controller that basically
  70. 2:26rumbles whenever I jump and whenever I
  71. 2:28land on the ground. But I also have this
  72. 2:30shift to sprint system where I hold
  73. 2:32right trigger and then it makes my
  74. 2:34character move really fast, but also my
  75. 2:37controller that's being connected is
  76. 2:39constantly vibrating. I don't think you
  77. 2:41can hear this, but yeah, my controller
  78. 2:43is vibrating
  79. 2:45constantly until I let go and then it
  80. 2:47basically just returns just like that.
  81. 2:49So, this is what I'm going to be
  82. 2:50teaching you how to add inside of your
  83. 2:51Roblox game and I hope that you find
  84. 2:53this tutorial to be helpful. And with
  85. 2:54that being said, let's go ahead and go
  86. 2:56straight into the episode. Now that we
  87. 2:58understand it, let's implement haptic
  88. 3:00service inside Roblox Studio. But before
  89. 3:02we begin, I want to mention that due to
  90. 3:04the nature of this tutorial being about
  91. 3:07controller vibrations, ideally I would
  92. 3:09want you to have a physical controller
  93. 3:11connected to your PC so that we can
  94. 3:13truly test the vibrations of our
  95. 3:15controllers once we implement them
  96. 3:17inside of our game. But if you don't
  97. 3:19have a physical controller, then there
  98. 3:20is an alternative and that is through
  99. 3:22controller emulation. And the whole idea
  100. 3:24behind controller emulation is that
  101. 3:27we're we're mapping out controls of a
  102. 3:29controller onto our keyboard so that we
  103. 3:32can emulate what it would be like to
  104. 3:34play on a controller. And as of
  105. 3:36recording this video, this is a beta
  106. 3:38feature, but if let's say you were
  107. 3:39watching this like a year from now, then
  108. 3:41this is probably out of beta and you can
  109. 3:43use and you can use this feature
  110. 3:45normally. But if you are watching this
  111. 3:46if it's a beta feature, then I'm going
  112. 3:48to show you how to enable it. So, what
  113. 3:50What going to do is go to file and then
  114. 3:52we're going to click on beta features.
  115. 3:54So, if we scroll down just a little bit,
  116. 3:56we should find something called gamepad
  117. 3:59emulator. So, we want to select this,
  118. 4:01and we want to hit save. So, it's going
  119. 4:03to ask us to restart studio, in which we
  120. 4:05are going to hit restart, and then we're
  121. 4:06just going to wait for this to load back
  122. 4:09up. All right, so now that we've loaded
  123. 4:10in, if we go to the test tab, then there
  124. 4:13should be a new button here under
  125. 4:15emulation called controllers. So, what
  126. 4:16we're going to do is click on this, and
  127. 4:18it's going to show a window down here
  128. 4:21that shows the mapping of what keys we
  129. 4:24have to press to emulate these specific
  130. 4:28buttons that are laid out on this
  131. 4:30controller. And we can test this out if
  132. 4:31we hit play.
  133. 4:33We can basically play the game as if we
  134. 4:35were playing on a controller, but
  135. 4:36instead we're just using our keyboard.
  136. 4:38So, if we want to use WASD, this is
  137. 4:41going to mimic what the left joystick is
  138. 4:43going to be like. And if we want to
  139. 4:45mimic the buttons over here, then we can
  140. 4:47just use the numbers 7 8 9 and 0 just
  141. 4:50like so. And this is a really effective
  142. 4:51emulator if we want to test the game
  143. 4:53using a controller if we don't have a
  144. 4:55physical controller. So, I think this
  145. 4:57would be really helpful for you to use,
  146. 4:58and with that being said, let's now go
  147. 5:00and continue with this tutorial. Okay,
  148. 5:02now let's start scripting haptic
  149. 5:04service. And the way we're going to do
  150. 5:05that is we're going to do this on the
  151. 5:07local side. So, we're going to insert a
  152. 5:09local script probably inside of, let's
  153. 5:12say, starter character scripts. So,
  154. 5:14let's hit the plus sign, and we're going
  155. 5:16to insert a local script, and we're
  156. 5:17going to delete the code that's over
  157. 5:18here. And we're first going to make
  158. 5:20reference to haptic service by saying
  159. 5:22local haptic service equals game colon
  160. 5:25get service haptic service just like
  161. 5:28this. Now, before we can start utilizing
  162. 5:31the vibration capabilities of our
  163. 5:33controller, we first have to check if
  164. 5:36the device that we plugged in can be
  165. 5:38vibrated. And if the motor that we're
  166. 5:40trying to change is also supported with
  167. 5:43this device as well. I'm going to show
  168. 5:44you and I'm going to show you both of
  169. 5:46these things. So, first what we have to
  170. 5:47do is check if it's vibration supported.
  171. 5:50So, we're going to say if haptic service
  172. 5:53{colon}
  173. 5:54is vibration supported open close
  174. 5:58parentheses. And this takes in a an enum
  175. 6:01value of a user input type. And And I'm
  176. 6:03going to show you what input type we're
  177. 6:04going to use here. So, we're going to
  178. 6:06say enum.userinputtype.
  179. 6:11And because we're testing out a
  180. 6:12controller, we're going to say gamepad
  181. 6:14one. So, we're going to hit enter. And
  182. 6:17then we're going to
  183. 6:20And if this is vibration supported, then
  184. 6:22we're just going to make a print
  185. 6:23statement saying that this device
  186. 6:26supports vibration just so that we know
  187. 6:28that this is working. So, what we're
  188. 6:30going to do is go to the game. We're
  189. 6:32going to hit test. We're going to enable
  190. 6:33our controller emulator. And we're going
  191. 6:35to hit play. So, then what we should see
  192. 6:37in the output is this device supports
  193. 6:39vibration, which is what we expected.
  194. 6:41So, the next thing we need to do is that
  195. 6:43if we can change specific parts of this
  196. 6:45controller to be able to vibrate. So,
  197. 6:46what we're going to do down here is say
  198. 6:48if haptic service {colon} is motor
  199. 6:52supported open and close parentheses.
  200. 6:54First thing we're going to do is add the
  201. 6:56input type, which is the same thing we
  202. 6:57did before. So, we're going to say
  203. 6:59enum.userinputtype.gamepad
  204. 7:01one. Now, for the second argument, this
  205. 7:04is what's called a vibration motor. Now,
  206. 7:07to basically explain these motors, let's
  207. 7:09go back to the game and I'm going to
  208. 7:11pull up the controller emulator again.
  209. 7:13So, based on the way this controller
  210. 7:15looks, there's multiple motors which are
  211. 7:18basically points inside of the
  212. 7:20controller that is allowed to be
  213. 7:22vibrated. So, there can be a certain
  214. 7:25section that basically makes up a
  215. 7:26majority of the controller called large,
  216. 7:28and we can make that motor vibrate. Or
  217. 7:30if you want to make a specific part of
  218. 7:32the controller, like let's say this
  219. 7:33right trigger area to vibrate, then we
  220. 7:35can do that as well. There are specific
  221. 7:37parts of this controller that we can
  222. 7:39vibrate, and these are essentially our
  223. 7:42motor points.
  224. 7:43So, that's essentially what we're trying
  225. 7:45to change here, and this is the function
  226. 7:47we're going to use to detect if this
  227. 7:49motor is supported with the controller
  228. 7:51that we have plugged in. So, what we're
  229. 7:53going to do is say enum.vibrationmotor,
  230. 7:57and the most common ones are usually
  231. 7:59large and small. So, in this case, we're
  232. 8:02going to test out large, and then we're
  233. 8:04going to say then, just like so. And so,
  234. 8:06this is going to check if it supports
  235. 8:07this motor. So, we're going to print
  236. 8:09saying uh large motor is supported, just
  237. 8:12like this. We're going to go and enable
  238. 8:15the controller again, and then we're
  239. 8:16going to hit play. So, then what we
  240. 8:18should see in the output is that this is
  241. 8:20also uh supported with a large motor, so
  242. 8:23that this is the motor we're going to
  243. 8:25vibrate uh through our controller.
  244. 8:28And so, I hope so far this is making
  245. 8:29sense to you. So, now that we know that
  246. 8:31this vibration motor is supported, we
  247. 8:33can now create controller vibrations
  248. 8:35using this function that I'm going to
  249. 8:36show you right now. So, we're going to
  250. 8:37drop two lines here, and what we're
  251. 8:39going to do is say
  252. 8:40hapticservice:setmotor,
  253. 8:44open and close parentheses just like
  254. 8:45this. And what we're going to do is pass
  255. 8:47in the user input type, so this is going
  256. 8:49to be enum.userinputtype.gamepad1,
  257. 8:53and then we're going to say uh
  258. 8:55enum.vibrationmotor.large,
  259. 8:58and finally, this takes in one more
  260. 9:00parameter, which is going to be the
  261. 9:02value of the vibration that we want to
  262. 9:05set. So, it's a value between zero and
  263. 9:07one. So, zero meaning that the vibration
  264. 9:10is off, and then one meaning that the
  265. 9:12vibration is turned on at its max. But,
  266. 9:14we can also set values in between zero
  267. 9:16and one as well. So, in this case, what
  268. 9:18I'm going to do is set this to one, and
  269. 9:20basically, what this does is it's going
  270. 9:22to switch the motor from zero to one,
  271. 9:25but it's constantly going to do this
  272. 9:26until we turn it off. And so, what we're
  273. 9:28going to do down here is put a task.wait
  274. 9:31statement for about, let's say, 2
  275. 9:33seconds, and then we're basically just
  276. 9:35going to copy this line, and we're going
  277. 9:37to paste it down here, and we're just
  278. 9:39going to set this back to zero. So, now
  279. 9:41what should happen is I'm also going to
  280. 9:42write some print statements here saying
  281. 9:44start motor, and then we're going to
  282. 9:47write another print statement here
  283. 9:48saying stop motor, just so that we can
  284. 9:50see that it's working inside of the
  285. 9:51script. So, if we go into the game,
  286. 9:53enable our controller, and then hit
  287. 9:55play, then what we should see in the
  288. 9:57output is we're starting the motor, and
  289. 10:00then after 2 seconds, it stopped the
  290. 10:01motor. Now, you can't really see this
  291. 10:03inside of the game if you don't have
  292. 10:05have a physical controller, but I have a
  293. 10:07physical controller connected inside of
  294. 10:09the game, and so I was able to feel the
  295. 10:12vibration coming out of my physical
  296. 10:14controller. But, you can trust me on
  297. 10:16this, it it is working.
  298. 10:18Now, I do want to add a bit of a side
  299. 10:19note to this and say that device
  300. 10:21vibration also works on mobile devices,
  301. 10:24but we're not going to be using the
  302. 10:25gamepad, but instead we're going to be
  303. 10:27using a different user input type. So,
  304. 10:29I'm going to show you what this looks
  305. 10:30like down here really quick. First thing
  306. 10:32we have to do is check if it's vibration
  307. 10:34supported, so we're going to say if
  308. 10:36haptic service colon is vibration
  309. 10:38supported, and what we're going to say
  310. 10:40here for the user input type is say
  311. 10:42touch, just like this. Touch is
  312. 10:44basically any device that is like a
  313. 10:47phone or a tablet that has a touch
  314. 10:50capability to them.
  315. 10:51So, if this is true, and what we're
  316. 10:53going to do here is basically say haptic
  317. 10:55service colon set motor, and then we're
  318. 10:57going to say enum.userinputtype.touch,
  319. 11:02and we can use the same motor we did up
  320. 11:04here with large. We can say
  321. 11:06enum.vibrationmotor.large,
  322. 11:09and then we can set this to one. And so,
  323. 11:10if you were to test this on a touch
  324. 11:12device like a phone or a tablet, then
  325. 11:15this should make the device vibrate as
  326. 11:17well. And this is not restricted to just
  327. 11:19controllers, but that's primarily what
  328. 11:21we're going to be doing for this
  329. 11:22tutorial. So, this is like a little
  330. 11:24thing I wanted to add on to here in case
  331. 11:26you wanted to do this for your touch
  332. 11:28devices as well. Now, it would be
  333. 11:30problematic to set off a bunch of motors
  334. 11:33and then turn them off later. So, it's
  335. 11:35like if I were to have large and small
  336. 11:38be turned on and then large and small be
  337. 11:40turned off, then we would have to
  338. 11:42manually turn on and turn off these
  339. 11:44different motors. Which is why it would
  340. 11:47be better if we had our own controller
  341. 11:49module script to help us regulate these
  342. 11:54motors that we set off and whenever we
  343. 11:56don't need to have these motors on
  344. 11:58anymore, then we can just have simple
  345. 12:00function to just turn them off. And in
  346. 12:01my opinion, this would be a more
  347. 12:03efficient way to handle our controller
  348. 12:06motors rather than just turning them on
  349. 12:07and off manually. So, here's what we're
  350. 12:09going to do. We're going to go to the
  351. 12:10game and we're going to insert a module
  352. 12:13script inside of replicated storage just
  353. 12:16like this and we're going to call this
  354. 12:18haptic controller just like this. And
  355. 12:21we're also going to name the module
  356. 12:23haptic controller just like this. And
  357. 12:27the first thing we're going to do is go
  358. 12:29to our local script copy our reference
  359. 12:31of the haptic service and we're going to
  360. 12:33do that up here. Now, there's going to
  361. 12:34be three functions that we're going to
  362. 12:36add to this haptic controller. The first
  363. 12:39thing is to check if this is motor
  364. 12:40supported and then two more functions
  365. 12:42are going to be related to starting the
  366. 12:44motor and then stopping the motor. So,
  367. 12:46we're going to say function haptic
  368. 12:49controller.
  369. 12:50dot is motor supported open and close
  370. 12:54parentheses and we're going to pass in
  371. 12:56two arguments here. So, the first thing
  372. 12:57is going to be the input type and then
  373. 13:00the vibration motor just like this and
  374. 13:02we're going to hit enter. And then what
  375. 13:04we're going to do is return haptic
  376. 13:06service colon is motor supported and
  377. 13:10we're just going to pass in the input
  378. 13:12type and the vibration motor just like
  379. 13:14this.
  380. 13:15And now we're going to add two more
  381. 13:16functions. We're going to say function
  382. 13:18haptic enter
  383. 13:22and then we're going to have one more
  384. 13:24for stop just like this. Now, what we're
  385. 13:28going to pass into both of these
  386. 13:29functions are the input type and the
  387. 13:33vibration motor, just like this. So,
  388. 13:36we're going to copy this and paste it
  389. 13:37down here. Now, for the stop function,
  390. 13:39this should be pretty easy. It's just
  391. 13:41one line. And basically, what we're
  392. 13:42going to do is just say haptic service,
  393. 13:46colon, set motor, open close
  394. 13:48parentheses. We're going to pass in the
  395. 13:50input type and we're going to pass in
  396. 13:52the vibration motor. And we're just
  397. 13:53simply going to set this to zero,
  398. 13:55because that's essentially what we're
  399. 13:56doing when we're stopping a motor from
  400. 13:58vibrating. And we're just setting the
  401. 14:00value of it to zero. And the same
  402. 14:01principle can basically be said about
  403. 14:04our start function as well, except
  404. 14:06instead of a constant value of zero,
  405. 14:08we're going to set this to an intensity
  406. 14:10variable that we're going We're going to
  407. 14:12set this to an intensity parameter,
  408. 14:14which is what we're going to add for our
  409. 14:15third parameter here. We're just going
  410. 14:17to say intensity. And then finally,
  411. 14:19we're going to add in one more
  412. 14:21parameter, which is going to be the
  413. 14:23duration of this vibration. So, we're
  414. 14:25going to replace this zero with the
  415. 14:27intensity. And now, uh the final thing
  416. 14:30we need to do for the start function is
  417. 14:33to give a duration as to how long we
  418. 14:35want this vibration to be set for. So,
  419. 14:38the way we're going to structure it is
  420. 14:39like this. We're going to drop two lines
  421. 14:41and we're going to put in a task. delay
  422. 14:45for however long the duration is. And
  423. 14:47then we're going to create a new
  424. 14:48function for this um task.delay function
  425. 14:51here. And so, basically, what we're
  426. 14:53going to do is simply just say haptic
  427. 14:55controller.stop, open close parentheses.
  428. 14:57And we're going to pass in the input
  429. 14:59type and the vibration motor, simply
  430. 15:01just like this. Now, the reason we're
  431. 15:03using task.delay is because we can have
  432. 15:06multiple We can have multiple motors be
  433. 15:09set off at the same time. So, we don't
  434. 15:12want the function to wait for a single
  435. 15:15motor to finish first before activating
  436. 15:17another one, which is why we're going to
  437. 15:19use a task.delay, because that allows us
  438. 15:21to activate multiple motors if we wanted
  439. 15:24to be able to do that.
  440. 15:25So, this is our basic function here, but
  441. 15:27if let's say we wanted to have an
  442. 15:29indefinite duration, meaning that if we
  443. 15:32want to start this vibration, but then
  444. 15:34we don't want it to stop until we
  445. 15:36specifically say that we want to stop
  446. 15:38this vibration, then we can do that
  447. 15:40using a value. Now, what is this value?
  448. 15:42Well, we can basically set it to be
  449. 15:43whatever value we want as long as it's
  450. 15:45not zero or anything greater than zero.
  451. 15:48So, let's make the value -1 in this
  452. 15:50case. So, what we're going to do is say,
  453. 15:52if duration is not equal to -1, then
  454. 15:57we're just going to take everything we
  455. 15:59have here and paste inside of here.
  456. 16:01Because if the value is -1, then we
  457. 16:03don't want to have a duration. But, if
  458. 16:06it's anything that's not -1, then we're
  459. 16:09going to add in a task.delay duration to
  460. 16:11this and then we're going to stop the
  461. 16:13controller. I hope that this has made
  462. 16:15sense to you. If it hasn't, then you can
  463. 16:16rewatch this part so that you can
  464. 16:18understand some of the parts that you
  465. 16:19weren't able to understand the first
  466. 16:21time, but generally, this is how our
  467. 16:24haptic controller function works. And
  468. 16:26now, let's implement this. Okay, so
  469. 16:27inside of our local script, we're first
  470. 16:29going to make reference to our haptic
  471. 16:31controller module by saying, local
  472. 16:33haptic controller equals require
  473. 16:37game.replicatedstorage:WaitForChild
  474. 16:40haptic controller just like this. Um
  475. 16:43we're also going to drop some lines down
  476. 16:45here at the bottom. And what we're going
  477. 16:46to do is say, if hapticcontroller.
  478. 16:50IsMotorSupported.
  479. 16:52And what we're going to throw in here is
  480. 16:53an Enum.UserInputType
  481. 16:55of Gamepad1 and then a vibration motor
  482. 16:59of, let's say, small in this case. Then
  483. 17:03we're going to make the small vibration
  484. 17:05motor activate by saying,
  485. 17:08hapticcontroller.Start,
  486. 17:11open close parentheses. And we're going
  487. 17:12to pass in the four arguments by saying,
  488. 17:14Enum.UserInputType.Gamepad1 and then
  489. 17:18enum.vibrationmotor.small
  490. 17:20and then we're going to add an intensity
  491. 17:22from 0 to 1. So, let's say 0.5 in this
  492. 17:25case. And then for the duration, well,
  493. 17:27we can set a duration to however many
  494. 17:29seconds we want. Let's say 2 seconds and
  495. 17:32this is automatically going to stop
  496. 17:34after 2 seconds. But let's say we wanted
  497. 17:36to have an indefinite time um for this
  498. 17:39function, we're just going to say -1 and
  499. 17:41so we would have to manually stop this
  500. 17:43ourselves. So, what we're going to do is
  501. 17:45let's say we have a task that wait here
  502. 17:47for about uh 2 seconds and then we're
  503. 17:50going to say haptic controller.stop
  504. 17:53open close parentheses and we're going
  505. 17:55to pass in the uh user input type. We
  506. 17:58can just copy this and paste it here.
  507. 18:00And then for the vibration motor, we can
  508. 18:02just copy this and paste it inside of
  509. 18:04here. And that basically stops it. So,
  510. 18:07this is the equivalent of this right
  511. 18:11here. So, if we start it, it's going to
  512. 18:12go for 2 seconds and then it's going to
  513. 18:14automatically stop within just one line.
  514. 18:17But uh we can essentially do the same
  515. 18:19thing just by having an indefinite
  516. 18:22period of time and so we're going to
  517. 18:23manually stop this vibration motor after
  518. 18:252 seconds have passed inside of our
  519. 18:27local script. And I hope that this has
  520. 18:30made sense to you. So, for today's
  521. 18:31challenge, I want you to create this
  522. 18:33shift to sprint system using the
  523. 18:35controller's right trigger to activate
  524. 18:38it. Now, one thing that I want you to do
  525. 18:40with this challenge is use the haptic
  526. 18:42controller uh module scripts that we
  527. 18:45created to add vibrations to our
  528. 18:48controller device when we are sprinting.
  529. 18:51So, as you can see in the output, uh
  530. 18:53there is a start vibration print
  531. 18:55statement and then there's an end
  532. 18:56vibration print statement. So, once we
  533. 18:58hold down right trigger, it's going to
  534. 19:00make our character sprint, but it's also
  535. 19:02going to start the vibration of our
  536. 19:05controller. And it doesn't matter which
  537. 19:07vibration motor you use um as long as
  538. 19:09you can see that the vibration is
  539. 19:10working. You can use large, you can use
  540. 19:12small, it doesn't really matter too
  541. 19:13much, but as long as you're holding down
  542. 19:15right trigger, then it's going to start
  543. 19:17the vibration and it's not going to stop
  544. 19:20until you let go the vibration. So,
  545. 19:22that's essentially my challenge for you
  546. 19:24for this episode. Go ahead and give it a
  547. 19:25try and once you think you have
  548. 19:27something going, then we're going to
  549. 19:29come back and script this ourselves. So,
  550. 19:31I will see you in just a little bit.
  551. 19:33Okay, so let's go back to our local
  552. 19:34script and we're going to comment out a
  553. 19:36couple of things. So, we're going to
  554. 19:38comment out everything that's up here
  555. 19:40and we're also going to comment out
  556. 19:41everything that is inside of here as
  557. 19:43well. So, all we have are the two
  558. 19:45references for Haptic Service and Haptic
  559. 19:47Controller. And we now need to make
  560. 19:49reference to more things in order for us
  561. 19:51to make this challenge work. And the
  562. 19:53first thing we need to do is make
  563. 19:54reference to User Input Service. So, up
  564. 19:56here we're going to say local User Input
  565. 19:59Service equals game colon get service
  566. 20:02User Input Service. And we're also going
  567. 20:04to need to make reference to our
  568. 20:05character by saying local character
  569. 20:07equals script.parent because this is
  570. 20:10located inside of Starter Character
  571. 20:11Scripts and we're going to locate the
  572. 20:13humanoid as well by saying local
  573. 20:15humanoid equals character wait for child
  574. 20:18humanoid just like this. So, now we have
  575. 20:21all of our references that we need. So,
  576. 20:22now we're going to use two functions
  577. 20:24from User Input Service. We're going to
  578. 20:26use input began and input ended. So,
  579. 20:28we're going to say User Input
  580. 20:30Service.Input Began colon connect
  581. 20:33function open and close parentheses.
  582. 20:35This takes in an input parameter and
  583. 20:37then we're going to hit enter.
  584. 20:39And then we're basically going to do the
  585. 20:40same thing, copy and paste it down here,
  586. 20:42but instead say input ended just like
  587. 20:45this. So, we first need to check if the
  588. 20:48input type is a gamepad. So, what we're
  589. 20:50going to do is say if
  590. 20:52input.UserInputType
  591. 20:55equals Enum.UserInputType.Gamepad1
  592. 20:59just like this,
  593. 21:00then we're going to check if the key
  594. 21:03code of the input matches the right
  595. 21:06trigger of our controller. So, what
  596. 21:08we're going to do is say if
  597. 21:10input.keycode
  598. 21:12equals enum.keycode.keycode.button
  599. 21:18R2.
  600. 21:20So, R2 is basically the right trigger of
  601. 21:23our controller. And so, that's basically
  602. 21:25how we represent it as a keycode, it's
  603. 21:27called button R2.
  604. 21:29So, inside of here, we're going to use
  605. 21:31one of the motors of our controller to
  606. 21:34make it vibrate using haptic controller.
  607. 21:36But, we need to do one more check and
  608. 21:38that is to check if it's motor
  609. 21:39supported. So, what we're going to do is
  610. 21:41say
  611. 21:42if haptic controller.is
  612. 21:45motor supported, we're going to throw in
  613. 21:47the input type of gamepad one, and we're
  614. 21:50also going to put the vibration motor
  615. 21:52of, let's say, small in this case. So,
  616. 21:56once we have all these checks, we can
  617. 21:57finally start vibrating the controller.
  618. 21:59So, what we're going to do is say haptic
  619. 22:01controller.start,
  620. 22:03and then we're just going to throw in
  621. 22:06our user input type and our vibration
  622. 22:08motor as the first two parameters, and
  623. 22:11then we're going to set the intensity of
  624. 22:12this to, let's say, one, and then we're
  625. 22:15going to set the duration to -1. Because
  626. 22:17what we want to do is hold down the
  627. 22:19controller for as long as possible, and
  628. 22:22then let go to then stop the vibration.
  629. 22:24So, that's why this is going to run an
  630. 22:26indefinite period of time.
  631. 22:28So, once we do this, then another thing
  632. 22:30we have to do is set the speed of our
  633. 22:32character's humanoid to be something
  634. 22:34larger. Um so, what we're going to do is
  635. 22:36say humanoid.walk speed equals, let's
  636. 22:39say, 48 because 16 is the default. And
  637. 22:42then we're going to make a print
  638. 22:43statement here saying that um we have
  639. 22:45started the uh vibration of our
  640. 22:48controller. So, now that we have this
  641. 22:51taken care of, we can basically copy the
  642. 22:53same thing and paste it down here um for
  643. 22:56our input ended. So, we're first going
  644. 22:58to check if we have a gamepad as our
  645. 23:00input type, and we're going to check if
  646. 23:01this was the button R2 key code that
  647. 23:04we're using as input.
  648. 23:06And then we check if it's motor
  649. 23:07supported, then we're going to replace
  650. 23:10this with stop instead of start. And we
  651. 23:13don't need the third and fourth
  652. 23:15parameter here uh if we're using the
  653. 23:17stop function. And we're also going to
  654. 23:19change the walk speed back to 16, and
  655. 23:21we're going to print stop vibration. And
  656. 23:24this is essentially how we use our
  657. 23:27haptic controller um
  658. 23:29module scripts that we created um for an
  659. 23:32example such as this. So now,
  660. 23:34if we go into the game, enable our
  661. 23:36controller emulator, and hit play, then
  662. 23:39what we should see is we can run around
  663. 23:42just like normal, but then once we hit
  664. 23:44right trigger, so if we hold P, then
  665. 23:48it's going to start the vibration of our
  666. 23:50controller, and it's also going to make
  667. 23:52our character move really fast. But then
  668. 23:54once we let go, then it's going to stop
  669. 23:56the vibration, and it's going to make
  670. 23:58our character walk in normal speed. And
  671. 23:59once again, um
  672. 24:01you can have my word on this, but my
  673. 24:03physical controller is vibrating um when
  674. 24:06when I do press um right trigger. So,
  675. 24:09this is basically how haptic service
  676. 24:11works, and I hope that you found this
  677. 24:13video to be extremely informative. So,
  678. 24:15that's pretty much going to be it for
  679. 24:16this episode on haptic service. If you
  680. 24:18found this video to be extremely
  681. 24:19informative, then I encourage you to
  682. 24:21leave a like on this video, and also
  683. 24:23subscribe to the channel if you haven't
  684. 24:25already. It would mean so much to me. Um
  685. 24:27and I would also like to give a
  686. 24:28shout-out to all of my Patreon members
  687. 24:30for supporting the work that I do. Um
  688. 24:32their contribution definitely motivates
  689. 24:33me to continue doing the work that I put
  690. 24:36out for this channel uh for you guys to
  691. 24:38watch. So, I'm very grateful for that.
  692. 24:39Please check out all of my other content
  693. 24:41that I have on this channel relating to
  694. 24:43other advanced scripting topics that you
  695. 24:44might find interesting. I will leave a
  696. 24:46link to context action service, which is
  697. 24:48basically creating mobile buttons for
  698. 24:50your game uh if you're interested in
  699. 24:52adding mobile support for your Roblox
  700. 24:53game, which I'm going to leave the link
  701. 24:55for you right here to watch. So, go
  702. 24:57ahead and watch that if you haven't
  703. 24:58already. With that being said, I will
  704. 25:00see you in the next episode.
  705. 25:03Take care.

About this transcript

This page contains the full transcript of Haptic Service (Controller Vibration) - Roblox Advanced Scripting #33 (2025) by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 4,907 words across 705 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.