Vehicle won't accelerate when touched and clicked as mobile support buttons

I have created a dream mobile support button which accelerates or breaks a vehicle, but it doesn’t do. So, there is an example of the script:

Mobile support event script:

local replicatedStorage = game.ReplicatedStorage

local accelVehicleEvent = replicatedStorage.AccelVehicleEvent
local brakeVehicleEvent = replicatedStorage.BrakeVehicleEvent

accelVehicleEvent.OnServerEvent:Connect(function(plr, vehicleseat)
	local throttled = false
	
	if not throttled then		
		throttled = true
		vehicleseat.Throttle = 1
	else
		throttled = false
		vehicleseat.Throttle = 0
	end
end)

brakeVehicleEvent.OnServerEvent:Connect(function(plr, vehicleseat)
	local backward = false
	
	if not backward then
		backward = true
		vehicleseat.Throttle = -1
	else
		backward = false
		vehicleseat.Throttle = 0
	end
end)

And the local script for these buttons:

local replicatedStorage = game.ReplicatedStorage

local accelVehicleEvent = replicatedStorage.AccelVehicleEvent
local brakeVehicleEvent = replicatedStorage.BrakeVehicleEvent

local currentVehicleSeat = workspace.Thomas.Chassis.VehicleSeat

local mobileController = script.Parent

local forwardBtn = mobileController.ForwardButton
local backwardBtn = mobileController.BackwardButton

local userInputService = game:GetService("UserInputService")

forwardBtn.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Touch and input.UserInputType == Enum.UserInputType.MouseButton1 then
		accelVehicleEvent:FireServer(currentVehicleSeat)
	end
end)

backwardBtn.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Touch and input.UserInputType == Enum.UserInputType.MouseButton1 then
		brakeVehicleEvent:FireServer(currentVehicleSeat)
	end
end)

How do I let the vehicle start accelerating or braking, which is touched by a mobile support button?

Local Script (for Mobile Buttons):

local replicatedStorage = game.ReplicatedStorage

local accelVehicleEvent = replicatedStorage.AccelVehicleEvent
local brakeVehicleEvent = replicatedStorage.BrakeVehicleEvent

local currentVehicleSeat = workspace.Thomas.Chassis.VehicleSeat

local mobileController = script.Parent

local forwardBtn = mobileController.ForwardButton
local backwardBtn = mobileController.BackwardButton

local userInputService = game:GetService("UserInputService")

forwardBtn.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then
		accelVehicleEvent:FireServer(currentVehicleSeat)
	end
end)

backwardBtn.InputBegan:Connect(function(input)
	if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then
		brakeVehicleEvent:FireServer(currentVehicleSeat)
	end
end)

Server Script (Mobile Support Event):

local replicatedStorage = game.ReplicatedStorage

local accelVehicleEvent = replicatedStorage.AccelVehicleEvent
local brakeVehicleEvent = replicatedStorage.BrakeVehicleEvent

local throttled = {}  -- Use a table to keep track of player throttling
local backward = {}  -- Use a table to keep track of player braking

accelVehicleEvent.OnServerEvent:Connect(function(plr, vehicleseat)
	if not throttled[plr] then
		throttled[plr] = true
		vehicleseat.Throttle = 1
	else
		throttled[plr] = false
		vehicleseat.Throttle = 0
	end
end)

brakeVehicleEvent.OnServerEvent:Connect(function(plr, vehicleseat)
	if not backward[plr] then
		backward[plr] = true
		vehicleseat.Throttle = -1
	else
		backward[plr] = false
		vehicleseat.Throttle = 0
	end
end)

Here are the changes made:

  1. In the local script, the logical operator or is used instead of and to check for either touch or mouse input. It should be input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1.

  2. In the server script, tables throttled and backward are used to keep track of player input. This ensures that each player’s input is handled independently, so multiple players can control their vehicles without interfering with each other.

dude i hope These changes should allow the vehicle to accelerate and brake when the mobile support buttons are touched.