Hello, So I'm making a game and I implemented a force shift lock system. It works but I tried to add it so when you hold down left alt you go out of the shift lock and when you release it you go back into shift lock and it doesn't work.

My code (In a localscript in StarterCharacterScripts):

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

RunService:BindToRenderStep("MouseLock", Enum.RenderPriority.Last.Value + 1, function()
	UserInputService.InputBegan:Connect(function(Input, GPE)
		if GPE then return end
		
		if UserInputService:IsKeyDown(Enum.KeyCode.LeftAlt) then
			UserInputService.MouseBehavior = Enum.MouseBehavior.Default
		elseif not UserInputService:IsKeyDown(Enum.KeyCode.LeftAlt) then
			UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter
		end
	end)
end)

RunService:BindToRenderStep("ForceShiftlock", Enum.RenderPriority.Camera.Value + 1, function()
	UserSettings():GetService("UserGameSettings").RotationType = Enum.RotationType.CameraRelative

	local currentCamera = workspace.CurrentCamera
	if not currentCamera then return end

	if (currentCamera.Focus.Position - currentCamera.CFrame.Position).Magnitude >= 0.99 then
		currentCamera.CFrame = currentCamera.CFrame*CFrame.new(1.75, 0, 0)
		currentCamera.Focus = CFrame.fromMatrix(currentCamera.Focus.Position, currentCamera.CFrame.RightVector, currentCamera.CFrame.UpVector)*CFrame.new(1.75, 0, 0)
	end
end)