This script to use the handbrake doesn't work

  1. What do you want to achieve?
    I’m trying to make a handbrake for a car

  2. What is the issue?
    When I press shift (the handbrake button) it fires a remote event that sets a value to true, in the car script it checks if the handbrake was pulled (if statement), if so it would lock the rear wheels (changes the rear wheel hinges to motors and sets their angular velocity to zero), I have no idea why this happens.

  3. What solutions have you tried so far?
    I tried to put the wheel locking thing into the script that handles the remote events and it didn’t work, I searched for a solution on the dev forums but I couldn’t find anything helpful, I guess my issue is very specific.

  4. Handbrake pull script

-- Services

local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Remote Events

local pulled = ReplicatedStorage.HandbrakePulled
local released = ReplicatedStorage.HandbrakeReleased

-- Booleans

local pressingShift = false

-- Car

local car = workspace.Car
local vehicleSeat = car.VehicleSeat

	-- Wheels
	local leftRearWheel = car.Controller.LR
	local rightRearWheel = car.Controller.RR

-- Parking / Drift mechanic

UserInputService.InputBegan:Connect(function(input)
	-- Locking the wheels

	if input.KeyCode == Enum.KeyCode.LeftShift then
		pressingShift = true

		pulled:FireServer()
	end
end)

UserInputService.InputEnded:Connect(function(input)
	-- Unlocking the wheels

	if input.KeyCode == Enum.KeyCode.LeftShift then
		pressingShift = false
		
		released:FireServer()
	end
end)
  1. Remote Event Handler
-- Services

local ReplicatedStorage = game:GetService("ReplicatedStorage")

-- Remote Events

local pulled = ReplicatedStorage.HandbrakePulled
local released = ReplicatedStorage.HandbrakeReleased

-- Car

local car = workspace.Car

local handbrakePulled = car.Controller.pressingShift.Value

-- Events

	-- Pulled
	pulled.OnServerEvent:Connect(function()
		handbrakePulled = true
	end)

	-- Released
	released.OnServerEvent:Connect(function()
		handbrakePulled = false
	end)
  1. Car script
-- Services

local RunService = game:GetService("RunService")

-- Wheels

local leftFrontWheel = script.LF
local rightFrontWheel = script.RF
local leftRearWheel = script.LR
local rightRearWheel = script.RR

-- Servos

local leftServo = script.ServoLeft
local rightServo = script.ServoRight

-- Car Stuff

local vehicleSeat = script.Parent.VehicleSeat

local speed = 100
local turnAngle = 60

local handbrakePulled = script.pressingShift.Value

-- Controller

RunService.Heartbeat:Connect(function()
	
	-- Checks if the gas is released
	
	if vehicleSeat.Throttle == 0 then
		
		-- Free the wheels
		
		-- Front Wheels

		leftFrontWheel.ActuatorType = Enum.ActuatorType.None
		rightFrontWheel.ActuatorType = Enum.ActuatorType.None
		
		-- Rear Wheels
		
		leftRearWheel.ActuatorType = Enum.ActuatorType.None
		rightRearWheel.ActuatorType = Enum.ActuatorType.None
	else
		
		-- Make the wheels a motor
		
		-- Front Wheels

		leftFrontWheel.ActuatorType = Enum.ActuatorType.Motor
		rightFrontWheel.ActuatorType = Enum.ActuatorType.Motor

		-- Rear Wheels

		-- leftRearWheel.ActuatorType = Enum.ActuatorType.Motor
		-- rightRearWheel.ActuatorType = Enum.ActuatorType.Motor
	end
	
	-- Checks if the handbrake is pulled
	
	if handbrakePulled == true then
		-- Lock the wheels
		leftRearWheel.ActuatorType = Enum.ActuatorType.Motor
		rightRearWheel.ActuatorType = Enum.ActuatorType.Motor

		leftRearWheel.AngularVelocity = 0
		rightRearWheel.AngularVelocity = 0
	else
		-- Rear Wheels

		-- leftRearWheel.AngularVelocity = speed * vehicleSeat.Throttle
		-- rightRearWheel.AngularVelocity = -speed * vehicleSeat.Throttle
	end
	-- Drive
	
	-- Front Wheels
	
	leftFrontWheel.AngularVelocity = speed * vehicleSeat.Throttle
	rightFrontWheel.AngularVelocity = -speed * vehicleSeat.Throttle
	

	-- Steer

	leftServo.TargetAngle = turnAngle * vehicleSeat.Steer
	rightServo.TargetAngle = turnAngle * vehicleSeat.Steer
end)

Any help would be appreciated!

1 Like

Any errors in the output? character limit

2 Likes

No there isn’t sadly, I’d hope there would.