How to get xbox controller / touch device to rumble?

If you’ve ever put the Admin HD model in your game and played it on Xbox, pressing B will reveal the “HD” icon and make the controller rumble for a short second.

  1. I want the controller / mobile device I’m using to rumble when I activate a text button.
  2. I want to know how to set the intensity of the rumbling.
1 Like

There is a solution for this located on the Roblox API documentation.

Pick out what you need from this.

Here is the quoted code:

    -- Services
    local HapticService = game:GetService("HapticService")
    local Players = game:GetService("Players")
    local RunService = game:GetService("RunService")
     
    -- Make sure we are running in a LocalScript.
    local player = Players.LocalPlayer
    assert(player,"This should be running in a LocalScript!")
     
    -- Setup Haptic Feedback Listener
    local function updateHapticFeedback()
    	-- Check if we currently have a character.
    	local character = player.Character
    	if character then
    		-- Do we have a Humanoid?
    		local humanoid = character:FindFirstChildOfClass("Humanoid")
    		if humanoid then
    			-- Are we in a vehicle seat?
    			local seatPart = humanoid.SeatPart
    			if seatPart and seatPart:IsA("VehicleSeat") then
    				-- Measure the current speed of the vehicle by taking the magnitude of the seat's velocity.
    				local speed = seatPart.Velocity.Magnitude 
    				
    				-- Measure the current throttle from the user.
    				local throttle = math.abs(seatPart.ThrottleFloat)
    				
    				-- Compute how much the controller should be vibrating.
    				local vibrationScale = math.min(1, (speed * throttle) / seatPart.MaxSpeed)
    				
    				-- Apply the vibration.
    				HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Small, vibrationScale)
    				
    				-- Return so the motor doesn't get reset.
    				return
    			end
    		end
    	end
    	
    	-- If nothing is happening, turn off the motor.
    	HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Small, 0)
    end
     
    -- Connect our haptic feedback listener to be updated 60 times a second.
    RunService.Heartbeat:Connect(updateHapticFeedback)

Further details can be found here:

3 Likes