Custom vehicle camera continues working after leaving vehicle

  1. What do you want to achieve? Keep it simple and clear!

I have a custom camera script for my vehicle, and I want it to stop working and reset player’s camera when I exit the vehicle

The idea is that at default, a custom cframe is used in the vehicle. When the player holds down left mouse button, it changes camera type to custom, and when released, changes back to the custom cframe.

  1. What is the issue? Include screenshots / videos if possible!

After leaving the vehicle, the custom camera script still responds to left mouse button input

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

Implementing debounce, creating functions for input, and manually disconnecting functions, none of which have worked.

local player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local car = script.Parent.Car.Value
local cam = workspace.CurrentCamera
local RS = game:GetService("RunService")
local E = false
local mouse = player:GetMouse()
local PlayerModule = require(player:WaitForChild"PlayerScripts":WaitForChild"PlayerModule")

local UserInputService = game:GetService("UserInputService")

local reset = true

local cancel = false


local event
local event2

local function cameraconnect()
	cam.CameraType = Enum.CameraType.Scriptable
	local cc = car.Body.Focus.Position+Vector3.new(0,3,0)-(car.DriveSeat.CFrame.lookVector*25)
	local framce = CFrame.new(cc,car.Body.Focus.Position)
	cam.CFrame = framce
	E = false
	event2:Disconnect()
end

local function freecam()
	cam.CFrame = car.DriveSeat.CFrame
	cam.CameraType = Enum.CameraType.Custom
	E = true
	event:Disconnect()
end

event = mouse.Button1Down:connect(freecam)
event2 = mouse.Button1Up:connect(cameraconnect)

	while car.DriveSeat:FindFirstChild("SeatWeld") do
		reset = true
		RS:BindToRenderStep("MCam",100,function()
			if E == false then
				cam.CameraType = Enum.CameraType.Scriptable
				local cc = car.Body.Focus.Position+Vector3.new(0,3,0)-(car.DriveSeat.CFrame.lookVector*25)
				local framce = CFrame.new(cc,car.Body.Focus.Position)
				cam.CFrame = framce
			end

		mouse.Button1Down:connect(freecam)

		mouse.Button1Up:connect(cameraconnect)

			if script.Parent.Values.MouseSteerOn.Value then
				cam.CameraType = Enum.CameraType.Scriptable
				local cc = car.Body.Focus.Position+Vector3.new(0,3,0)-(car.DriveSeat.CFrame.lookVector*25)
				local framce = CFrame.new(cc,car.Body.Focus.Position)
				cam.CFrame = framce
			end
		end)
		wait(1)
		reset = false
	end

	event:Disconnect()
	event2:Disconnect()
	RS:UnbindFromRenderStep("MCam")
	cam.CameraSubject = player.Character.Humanoid
	cam.CameraType = Enum.CameraType.Custom
	cam.CFrame = player.Character.Head.CFrame

Is the script a local script located in the Plugins for the A-Chassis?

yes, it is, sorry for the late reply

if you look in your character is the script still there when you exit the vehicleSeat. if not add a check to the DriveSeat. with Occupant and if Occupant == nil then script:Destroy()

You have to make a custom Camera for that.
Additionally, I’ve noticed you set the Camera type to ‘Custom’ in Function freecam()

cam.CameraType = Enum.CameraType.Custom

This is probably why the input is still being detected.