HapticService

Show Deprecated
Not Creatable
Service
Not Replicated

Modern controllers and devices have motors built‑in to provide haptic feedback. Adding rumbles and vibrations can provide subtle feedback that is hard to convey through visuals or audio alone.

Roblox supports haptics for the following devices:

  • Android and iOS phones supporting haptics including most iPhone, Pixel, and Samsung Galaxy devices
  • PlayStation gamepads
  • Xbox gamepads
  • Quest Touch controller

Summary

Methods

Properties

Methods

GetMotor

Returns the current vibration value set to the specified UserInputType and Enum.VibrationMotor. This will not return anything if SetMotor() has not been called prior.

Parameters

The specified Enum.UserInputType.

vibrationMotor: Enum.VibrationMotor

The specified Enum.VibrationMotor.


Returns

The current vibration value set to the specified Enum.UserInputType and Enum.VibrationMotor or nil if SetMotor() has not been called prior.

IsMotorSupported

Returns true if the specified motor is available to be used with the specified Enum.UserInputType.

Parameters

The specific Enum.UserInputType being checked for Enum.VibrationMotor support.

vibrationMotor: Enum.VibrationMotor

The specified Enum.VibrationMotor checked to see if it supports the specified Enum.UserInputType.


Returns

Boolean of true if the specified motor is available to be used with the specified Enum.UserInputType, false if not.

IsVibrationSupported

Returns true if the specified Enum.UserInputType supports haptic feedback.

Parameters

The specified Enum.UserInputType checked to see if it supports haptic feedback.


Returns

Boolean of true if the specified Enum.UserInputType supports haptic feedback.

SetMotor

void

Sets the vibration intensity of the specified inputType and vibrationMotor. Note that almost all usage cases specify Enum.UserInputType.Gamepad1 for inputType which is internally mapped to the device's respective hardware.

Parameters

The specified Enum.UserInputType.

vibrationMotor: Enum.VibrationMotor

The specified Enum.VibrationMotor.

vibrationValues: Tuple

How intensely the motor should vibrate. Only uses the first value in the tuple, which should be a number.


Returns

void

Code Samples

This example makes the small motor vibrate depending on how much pressure is applied to the left trigger, and the large motor vibrate depending on how much pressure is applied to the right trigger.

HapticService:SetMotor()

local UserInputService = game:GetService("UserInputService")
local HapticService = game:GetService("HapticService")
local cachedInputs = {}
local keyToVibration = {
[Enum.KeyCode.ButtonL2] = Enum.VibrationMotor.Small,
[Enum.KeyCode.ButtonR2] = Enum.VibrationMotor.Large,
}
local function onInputChanged(property)
if property == "Position" then
HapticService:SetMotor(inputType, vibrationMotor, input.Position.Z)
end
end
local function onInputBegan(input)
if not cachedInputs[input] then
local inputType = input.UserInputType
if inputType.Name:find("Gamepad") then
local vibrationMotor = keyToVibration[input.KeyCode]
if vibrationMotor then
-- Watch this input manually to accurately update the vibration motor
cachedInputs[input] = input.Changed:Connect(onInputChanged)
end
end
end
end
UserInputService.InputBegan:Connect(onInputBegan)

Events