Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

HapticService's Vibration doesn't work Online?

I tried to add up some stuff on my "test" place, and one of them is vibration. I tried it in Studio, and it works. But when I go online, it doesn't vibrate. My vibration code is:

if game.HapticService:IsVibrationSupported(Enum.UserInputType.Gamepad1) and game.HapticService:IsMotorSupported(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large) then
	game.HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0.6)
	wait(0.3)
	game.HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0)
end

If that is actually a bug, someone post this problem on Developer Forum. (I don't have a DevForum account >,>)

1 answer

✓ Accepted answer

There is a small delay when roblox starts to when the controller is connected so you need to wait for the controller to be connected you can use the events GamepadConnected and GamepadDisconnected which fires when a controller is connected and disconnected.

Example:-

-- services
local userInpServ = game:GetService('UserInputService')
local hptServ = game:GetService('HapticService')

-- wait for game pad
print('Waiting for gamepad')
local gamePad = userInpServ.GamepadConnected:Wait() -- wait for a controller
print('Gamepad found', gamePad)

-- motor
if hptServ:IsMotorSupported(gamePad, Enum.VibrationMotor.Large) then
	hptServ:SetMotor(gamePad, Enum.VibrationMotor.Large, 0.6)
	wait(0.3)
	hptServ:SetMotor(gamePad, Enum.VibrationMotor.Large, 0)
else
	print('Motor not supported')	
end

I hope this helps.

7 comments

0

How can I make it ignore non-gamepad users? (Also, doesn't work on an on-going code)

0

What controller are you using?

0
0

Still the same problem with GetConnectedGamePad solution. (I'm using a USB Xbox 360 controller)

0

(And by the same problem I mean the same problem as the post)

0

This needs to be a local script, can you check what is being ran. This code does work for my Xbox controller.

0

Whoops, I forgot that. facepalms

This discussion is preserved as it was. New answers, comments, and votes are closed.