I’ve been trying to use HapticService to make the player’s phone vibrate whenever an UI button is pressed. For some reason it just doesn’t vibrate even though the function runs perfectly fine.
Code:
local hapticService = game:GetService("HapticService")
local CAN_VIBRATE = hapticService:IsMotorSupported(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Small)
local lastTap
local VIBRATION_LENGTH = 1 / 60
local function Vibrate()
if CAN_VIBRATE then
local thisTick = tick()
lastTap = thisTick
hapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Small, 1)
task.wait(VIBRATION_LENGTH)
if lastTap == thisTick then
hapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Small, 0)
end
end
end
button.MouseButton1Click:Connect(Vibrate)
Yeah i’ve added some print()s in the code and it works perfectly (meaning that CAN_VIBRATE is true), though it’s just not vibrating. Do i need to enable something in my game?
I think something’s wrong with my game. I tried this script in a new experience and it works perfectly. When i tried it in my game, nothing seems to happen. Thanks anyway
Hmm… very odd indeed. Do you use HapticService anywhere else in your game? I have no idea what the issue is but maybe two different vibrations are fighting eachother. You can find checks for HapticService by using the “Find All / Replace All” option in the View tab.
I think it’s intended so then when you have voice chat enabled the device vibrating doesn’t interfere with the microphone (like being able to hear the vibrations, but that’s just my hypothesis
Voice chat might take priority in resource allocation over haptic feedback. Also, mobile platforms often have restrictions on simultaneous use of certain features for performance or security reasons, so that may be another reason. I’m not entirely sure though. But thanks @0Tenth again for pointing it out