print 'Hello world!'
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.Large, 1)
		end
	else
		-- No one is in the seat anymore, make sure the rumble stops
		driving = false
		HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Large, 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.Small, speedPercentage)
	else
		-- Player isn't driving, make sure the small motor is off
		HapticService:SetMotor(Enum.UserInputType.Gamepad1, Enum.VibrationMotor.Small, 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

This is all I have I do have a car Named "Car" With a Vehicle Seat Named "Seat" But It still won't vibrate controller in a Local Script In Workspace

2 comments

0

Does it even print 'Hello world'? As far as I know, LocalScripts don't run in workspace.

0

no