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.

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

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

True if the specified Enum.UserInputType supports haptic feedback.

SetMotor

void

Sets the vibration intensity of the specified UserInputType and Enum.VibrationMotor. Note that almost all use cases specify Gamepad1 as the UserInputType.

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

HapticService:SetMotor

local UserInputService = game:GetService("UserInputService")
local HapticService = game:GetService("HapticService")
local cachedInputs = {} -- Note that we use a cache so we don't attach a Changed event more than once.
local keyToVibration = {
[Enum.KeyCode.ButtonL2] = Enum.VibrationMotor.Small,
[Enum.KeyCode.ButtonR2] = Enum.VibrationMotor.Large,
}
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 InputObject manually so we can accurately update the vibrationMotor.
local function onChanged(property)
if property == "Position" then
HapticService:SetMotor(inputType, vibrationMotor, input.Position.Z)
end
end
cachedInputs[input] = input.Changed:Connect(onChanged)
end
end
end
end
UserInputService.InputBegan:Connect(onInputBegan)

Events