Third Person Gun Help

Ok, so I have a thirdperson script for a Gun, and i want whenever the gun is equipped to go into third person, and it does that but, it will only switch on MouseButton1 and idk how to fix it. I’ll leave code here and an gif of what happens.

local UserInputService = game:GetService("UserInputService")
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")

local camera = workspace.CurrentCamera
local Player = Players.LocalPlayer
local cameraOffset = Vector3.new(2,2,8)

local mouse = Player:GetMouse()
Player.CharacterAdded:connect(function(char)
	local humanoid = char:WaitForChild("Humanoid")
	local rootPart = char:WaitForChild("HumanoidRootPart")

	local cameraAngleX = 0
	local cameraAngleY = 0

	humanoid.AutoRotate = false

	local function playerInput(actionName, inputState, inputObject)
		if inputState == Enum.UserInputState.Change then
			cameraAngleX -= inputObject.Delta.X
			cameraAngleY = math.clamp(cameraAngleY - inputObject.Delta.Y * 0.4, -75, 75)
		end
	end
	ContextActionService:BindAction("PlayerInput",playerInput,false,Enum.UserInputType.MouseMovement, Enum.UserInputType.Touch)

	RunService:BindToRenderStep("CameraUpdate", Enum.RenderPriority.Camera.Value, function()
		if script.Parent.Parent == char then
			local startCFrame = CFrame.new(rootPart.CFrame.Position)*CFrame.Angles(0,math.rad(cameraAngleX),0) * CFrame.Angles(math.rad(cameraAngleY),0,0)
			local cameraCFrame = startCFrame:PointToWorldSpace(cameraOffset)
			local cameraFocus = startCFrame:PointToWorldSpace(Vector3.new(cameraAngleX,cameraOffset.Y, -100000))

			camera.CFrame = CFrame.lookAt(cameraCFrame,cameraFocus)

			local lookingCFrame = CFrame.lookAt(rootPart.Position, camera.CFrame:PointToWorldSpace(Vector3.new(0,0,-100000)))

			rootPart.CFrame = CFrame.fromMatrix(rootPart.Position,lookingCFrame.XVector,rootPart.CFrame.YVector)
		end
	end)
end)

local function focusControl(actionName, inputState, inputObject)
	if script.Parent.Parent:FindFirstChild("Humanoid") then
		if inputState == Enum.UserInputState.Begin then
			camera.CameraType = Enum.CameraType.Scriptable

			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
			--UserInputService.MouseIconEnabled = false
			mouse.Icon = "rbxassetid://8230755404"
		end
	else
		camera.CameraType = Enum.CameraType.Custom
		mouse.Icon = [[]]
		Player.Character.Humanoid.AutoRotate = true
	end
end--                             string name     function  add touch button inputTypes
ContextActionService:BindAction("FocusControl", focusControl, false, Enum.UserInputType.MouseButton1, Enum.UserInputType.Touch, Enum.UserInputType.Focus)

If you are talking about when the tool unequip it stay as the 3rd person but if it’s that you nead to put cameratype = custom when thé player unequip the tool

Ok. Ill try it right now. Ill let you know what happens

Literally just lost a huge save file. Good thing I have the code here.

yeah alway save your thing before doing it lol!

it crashed thats why, but actually i have another problem. Tool.Activated doesnt work

Use player:GetMouse it could help you with your thing