Haptic feedback won't play on republished game

Hello,

So I have a module script that controls gui effects. It also includes a function that plays a haptic on supported devices. However, I published the game to a group and now the haptic effect doesn’t work. Here is the script, it is exactly the same in the group game and my private one:

local TweenService = game:GetService("TweenService")
local SoundService = game:GetService("SoundService")
local HapticService = game:GetService("HapticService")

local ButtonModule = {}

-- Function to play a sound
local function playSound(sound)
	SoundService:PlayLocalSound(SoundService:WaitForChild(sound))
end

-- Function to play haptic feedback
local function playHaptic()
	if HapticService:IsVibrationSupported(Enum.UserInputType.Gamepad1) then 
		HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0.8) 
		task.wait(0.05) 
              print("HapticComplete")
		HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0) 
	end
end

function ButtonModule.SetupButton(button) 
	print(button.Name)

	if button:FindFirstChild("Pet") then
		local viewportFrame = button:FindFirstChild("Pet")

		if viewportFrame:IsA("ViewportFrame") then
			local originalScale = viewportFrame.Size
			local hoverScale = UDim2.new(originalScale.X.Scale * 1.08, 0,originalScale.Y.Scale * 1.08 ,0 )
			local pressScale = UDim2.new(originalScale.X.Scale * 0.92,0,originalScale.Y.Scale * 0.92,0)

			local function scaleViewportFrame(size)
				local tweenInfo = TweenInfo.new(0.07, Enum.EasingStyle.Sine, Enum.EasingDirection.Out)
				local properties = {Size = size}
				local tween = TweenService:Create(viewportFrame, tweenInfo, properties)
				tween:Play()
			end

			button.MouseEnter:Connect(function()
				scaleViewportFrame(hoverScale)
				playSound("click2")
			end)

			button.MouseLeave:Connect(function()
				scaleViewportFrame(originalScale)
			end)

			button.MouseButton1Down:Connect(function()
				scaleViewportFrame(pressScale)
				playHaptic()
			end)

			button.MouseButton1Up:Connect(function()
				scaleViewportFrame(hoverScale)
				playSound("click2")
			end)
		end
	else
		local size = UDim2.new(button.Size.Width.Scale, 0, button.Size.Height.Scale, 0) 

		button.MouseEnter:Connect(function()
			button:TweenSize(UDim2.new(size.X.Scale * 1.04, 0, size.Y.Scale * 1.04, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.06, true)
			playSound("click2")
		end)

		button.MouseLeave:Connect(function()
			button:TweenSize(size, Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.06, true)
		end)

		button.MouseButton1Down:Connect(function()
			button:TweenSize(UDim2.new(size.X.Scale * 0.96, 0, size.Y.Scale * 0.96, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.06, true)
			playHaptic()
		end)

		button.MouseButton1Up:Connect(function()
			button:TweenSize(UDim2.new(size.X.Scale * 1.04, 0, size.Y.Scale * 1.04, 0), Enum.EasingDirection.InOut, Enum.EasingStyle.Sine, 0.06, true)
			playSound("click2")
		end)
	end
end

return ButtonModule

It prints the “HapticComplete” in both games.
Could there be some setting I need to enable?

I don’t know all that much about the haptics api so I’m not gonna be of much help, but could you try increasing the delay to turn off the haptics? something along the lines of this:

local function playHaptic()
	if HapticService:IsVibrationSupported(Enum.UserInputType.Gamepad1) then 
		HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0.8) 
		task.wait(0.5) 
        print("HapticComplete")
		HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0) 
	end
end

This obviously shouldn’t be a permanent change, I just want to see if there’s a chance the haptics are being turned off before your controller ever gets the signal to turn them on.

It doesn’t fire the haptic, but still prints

Ah gotcha. Do you mind printing out IsMotorSupported within that function?

local function playHaptic()
	print(HapticService:IsVibrationSupported(Enum.UserInputType.Gamepad1))
	if HapticService:IsVibrationSupported(Enum.UserInputType.Gamepad1) then 
		HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0.8) 
		task.wait(0.5)
		HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0) 
	end
end

prints true

No I’m talking about printing IsMotorSupported, not IsVibrationSupported.
It should look something like this

local function playHaptic()
    local InputDevice = Enum.UserInputType.Gamepad1
	if HapticService:IsVibrationSupported(InputDevice) then
        local Motor = Enum.VibrationMotor.Large
        print(HapticService:IsMotorSupported(InputDevice, Motor)
		HapticService:SetMotor(InputDevice, Motor, 0.8) 
		task.wait(0.5)
		HapticService:SetMotor(InputDevice, Motor, 0) 
	end
end

Oh, sorry. it still prints true. The script works perfectly in the other game, but the one I published to the group doesn’t work

No worries! Sorry but it doesn’t look I’ll be much help then unfortunately :confused:

1 Like