Why is my controller not vibrating?

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)
1 Like

This script seems to be a server script. I believe HapticService and the other user input variables are better to be used with a LocalScript.

3 Likes

Even in a Local script it doesn`t work!

2 Likes

I don’t exactly know why it isn’t working, but I can suggest a couple of things:

  1. Set up print() statements in the code to better understand what’s going on in the scripts.
  2. If you haven’t already, try migrating the vibration code to the LocalScript that fires the remote to the server.

Hopefully this helps!

4 Likes
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?

3 Likes

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.

1 Like

Server Script in a Tool of course!

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)

So it should work?

1 Like

I set up the code you sent in a Tool and it worked. I would advise checking to see if your PS5 controller is compatible with vibrations.

1 Like

Yeah maybe it’s just not i don`t know

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