Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

HapticService's Vibration doesn't work Online?

Asked by 7 years ago
Edited 7 years ago

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

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

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.

0
How can I make it ignore non-gamepad users? (Also, doesn't work on an on-going code) MinePlayersPE1 33 — 7y
0
What controller are you using? User#5423 17 — 7y
0
You would check that there are no game pads connected, http://wiki.roblox.com/index.php?title=API:Class/UserInputService/GetConnectedGamepads User#5423 17 — 7y
0
Still the same problem with GetConnectedGamePad solution. (I'm using a USB Xbox 360 controller) MinePlayersPE1 33 — 7y
View all comments (3 more)
0
(And by the same problem I mean the same problem as the post) MinePlayersPE1 33 — 7y
0
This needs to be a local script, can you check what is being ran. This code does work for my Xbox controller. User#5423 17 — 7y
0
Whoops, I forgot that. *facepalms* MinePlayersPE1 33 — 7y
Ad

Answer this question