Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Haptic service works in studio not in game help please?

Asked by 8 years ago
Edited 8 years ago

I have 2 scripts for the Haptic service stuff

print 'Hello world or goodbye?!?!?!?!?!?!?!!?!?!?!?!?!?!?!?!?!??!?!?!?!!?'
print(math.random(0,999999999))
print(math.random(0,999999999))
print(math.random(0,999999999))
print(math.random(0,999999999))
print(math.random(0,999999999))

local HapticService = game:GetService("HapticService")

local Car = workspace:WaitForChild("Car")
local Seat = Car:WaitForChild("VehicleSeat")
local driving = false

wait()

local function onOccupantChanged()
    -- Check whether someone is getting in the seat or out of it
    if Seat.Occupant then       
        -- Get the player that sat in the seat and check if it's the local player
        local player = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
        if player == game.Players.LocalPlayer then
            -- Local player is sitting in the seat, start low rumble
            driving = true
            HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Small, 1)
            print 'VIBRATING SMALL'
        end
    else
        -- No one is in the seat anymore, make sure the rumble stops
        driving = false
        HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Small, 0)   
    end
end

local function update()
    -- Check if the local player is driving
    if driving then
        -- Get the speed of the seat so we can set the small rumble proportionally
        local velocity = Seat.Velocity.magnitude
        local speedPercentage = velocity * Seat.MaxSpeed
        HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, speedPercentage)
        print 'VIBRATING LARGE'
    else
        -- Player isn't driving, make sure the small motor is off
        HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 0)
    end
end

-- Bind Seat's Changed event
Seat.Changed:connect(function(property)
    if property == "Occupant" then
        onOccupantChanged()
    end
end)

-- Setup update loop
while wait() do
    update()
end

SCRIPT 2

print 'Hello world!'
local HapticService = game:GetService("HapticService")
local isVibrationSupported = HapticService:IsVibrationSupported(Enum.UserInputType.Gamepad1)
local largeSupported = false
if isVibrationSupported then
    largeSupported = HapticService:IsMotorSupported(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large)
    print 'Large Is CHECKED VIA HapticService '
end
local smallSupported = false
if isVibrationSupported then
    smallSupported = HapticService:IsMotorSupported(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Small)
    print 'Small Is CHECKED VIA HapticService '
end
local lefttriggerSupported = false
if isVibrationSupported then
    lefttriggerSupported = HapticService:IsMotorSupported(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.LeftTrigger)
    print 'lefttrigger Is CHECKED VIA HapticService '
end
local righttriggerSupported = false
if isVibrationSupported then
    righttriggerSupported = HapticService:IsMotorSupported(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.RightTrigger)
    print 'righttrigger Is CHECKED VIA HapticService '
end

NOTE I am getting it to work in studio [Using a Xbox 360 Wired Controller Large and Small Motors] but when i go and publish it and play it on roblox it won't print that the motors have been checked [Script #2]

Answer this question