Unable to make mobile device vibrate using HapticService

Hey developers

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)

(yes, my phone can vibrate)

Any help is appreciated!

1 Like

You’re trying to do it on a gamepad

Could you elaborate please?

(max chars)

Yeah actually don’t listen to me, I just searched some stuff up.

Have you checked to make sure CAN_VIBRATE is set to true?

1 Like

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?

Could this post help? I’ve never really dabbled in vibrations. Good opportunity to learn something new lol

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.

1 Like

Does your game have Spatial Voice/Voice Chat enabled? Currently it is not compatible with HapticService on mobile devices

1 Like

I knew there was something up with my game and not the code itself. Thank you!!

1 Like

That’s really strange. I’d better keep that in mind! Any idea why that happens?

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

I don’t think it’d interrupt the sound. Vibrations don’t make THAT big of a noise, do they?

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

1 Like

wait a minute since when was hapticservice a thing
boy i can make a vibrator now!

Ah, I see! You learn something new every day, I guess. Thanks for unintentionally introducing me to HapticService :joy:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.