Can you tell me why my controller is not vibrating?
local tool = script.Parent
local remote = script.Parent.RemoteEvent
local healing = false
local glasssound = script.Parent.Glass
local trinksound = script.Parent.Trink
local HapticService = game:GetService("HapticService")
local gamepad = Enum.UserInputType.Gamepad1
local touch = Enum.UserInputType.Touch
local isVibrationSupported = HapticService:IsVibrationSupported(gamepad)
local isVibrationSupported2 = HapticService:IsVibrationSupported(touch)
remote.OnServerEvent:Connect(function(player)
if healing == true then return end
if player.Character.Humanoid.Health <= 100 then
healing = true
local animationTrack = player.Character.Humanoid:LoadAnimation(script.Parent.Handle.Animation)
animationTrack:Play()
glasssound:Play()
if isVibrationSupported or isVibrationSupported2 then
local largeMotor = HapticService:IsMotorSupported(gamepad, Enum.VibrationMotor.Small)
local largeMotor2 = HapticService:IsMotorSupported(touch, Enum.VibrationMotor.Small)
if largeMotor or largeMotor2 then
HapticService:SetMotor(gamepad, Enum.VibrationMotor.Small, 0.5)
HapticService:SetMotor(touch,Enum.VibrationMotor.Small, 0.5)
end
end
wait(0.5)
trinksound:Play()
player.Character.Humanoid.Health += 30
wait(50)
healing = false
end
end)
local UserInputService = game:GetService("UserInputService")
local HapticService = game:GetService("HapticService")
local ControllerVibrationsEnabled = false
script.Parent.RemoteEvent.OnClientEvent:Connect(function()
if UserInputService:GetGamepadConnected(Enum.UserInputType.Gamepad1) then
if HapticService:IsMotorSupported(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large) then
ControllerVibrationsEnabled = true
end
end
if ControllerVibrationsEnabled then
print("vibrating")
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
end)
It prints but it is still not vibrating my ps5 controller connected with my pc via usb! Maybe my controller is broken or incompatible?
I tested out the code you sent here without the script.Parent.RemoteEvent.OnClientEvent:Connect(function() portion with my Xbox 360 controller via USB and it worked. If the client is going to receive the vibration using a remote event, I would double check to make sure your FireClient() statement has the correct parameters and double check to make sure the LocalScript is where it should be to run. Also, the issue could possibly be your ps5 controller considering it worked with my xbox 360 controller when I put a portion of the script under StarterPlayerScripts. Since it printed and still didn’t work for you, my best assumption is that it is your controller.
local debounce = false
local tool = script.Parent
local HapticService = game:GetService("HapticService")
tool.Activated:Connect(function()
local playerCharacter = script.Parent.Parent
local player = game:GetService("Players"):GetPlayerFromCharacter(playerCharacter)
if debounce == false and not playerCharacter:FindFirstChildOfClass("ForceField") then
local forceField = Instance.new("ForceField",playerCharacter)
forceField.Visible = true
script.shield_blockmetal1:Play()
debounce = true
script.Parent.RemoteEvent:FireClient(player)
wait(20)
forceField:Destroy()
script.Parent.RemoteEvent:FireClient(player)
script["Wooden Gate Crash 2 (SFX)"]:Play()
wait(120)
debounce = false
end
end)
The Remote Event is also in the Tool
Local Script located in the Tool
local UserInputService = game:GetService("UserInputService")
local HapticService = game:GetService("HapticService")
local ControllerVibrationsEnabled = false
script.Parent.RemoteEvent.OnClientEvent:Connect(function()
if UserInputService:GetGamepadConnected(Enum.UserInputType.Gamepad1) then
if HapticService:IsMotorSupported(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large) then
ControllerVibrationsEnabled = true
end
end
if ControllerVibrationsEnabled then
print("vibrating")
HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0.5) --the last number can be anywhere from 0-1.
task.wait(3) --delay before turning motor back off
HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0)
end
end)