HapticService

Show Deprecated
Not Creatable
Service
Not Replicated

Properties

Methods

GetMotor

Parameters

Default Value: ""
vibrationMotor: Enum.VibrationMotor
Default Value: ""

Returns

IsMotorSupported

Parameters

Default Value: ""
vibrationMotor: Enum.VibrationMotor
Default Value: ""

Returns

IsVibrationSupported

Parameters

Default Value: ""

Returns

SetMotor

()

Parameters

Default Value: ""
vibrationMotor: Enum.VibrationMotor
Default Value: ""
vibrationValues: Tuple
Default Value: ""

Returns

()

Code Samples

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