Hello! Im trying to code something to make the players phone vibrate. Is this possible? If yes then can someone show me how to do it?
3 Likes
have you considered looking into HapticService? it would be perfect for your situation.
OH! Im a little confused though on how to use this. Do you mind providing an example?
local ControllerVibrationsEnabled = false
if UserInputService:GetGamepadConnected(Enum.UserInputType.Gamepad1) then
if HapticService:IsMotorSupported(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large) then
ControllerVibrationsEnabled = true
end
end
--somewhere else in your script
if ControllerVibrationsEnabled then
HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0.5) --the last number can be anywhere from 0-1.
task.wait(1) --delay before turning motor back off
HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0)
end
by the way, thank you for making this post because i didnt know that haptic service existed until just now.
Edit: I just realized that you said phone. The same script should work but remove the UserInputService:GetGamepadConnected
Updated Script
local HapticService = game:GetService("HapticService")
local PhoneVibrationsEnabled = false
if HapticService:IsMotorSupported(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large) then
PhoneVibrationsEnabled = true
end
--somewhere else in your script
if PhoneVibrationsEnabled then
HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0.5) --the last number can be anywhere from 0-1.
task.wait(1) --delay before turning motor back off
HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0)
end
4 Likes
Is it possible to use :SetMotor() within a
script.parent.mousebutton1click:connect(function()
hapticservice:SetMotor(nil, Enum.VibrationMotor.Large, 0.6)
end
It should be possible, just make sure that you replace nil
with something else.