How can I stop camera shake when I'm out of first person?

I currently have a script written down below that is in charge of sprinting and camera shake. As of right now when you press “c” it locks you in first person and when you press “c” again it takes you out. And the camera shake works perfectly, it doesn’t shake when you’re not in first person and it shakes when you are. But now the problem is, if you go into first person and start sprinting, the camera shake works, but once you go back out of first person, the camera shake keeps going. Any help is appreciated, thanks!

Here’s a video on what’s happening,

local script in StarterCharacterScripts vvv

local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local hum = script.Parent:WaitForChild('Humanoid')

local firstperson = false
sprinting = false

UIS.InputBegan:Connect(function(input, processed)
	if sprinting == false and input.KeyCode == Enum.KeyCode.LeftShift then
		sprinting = true
		hum.WalkSpeed = 20

		if sprinting == true and input.KeyCode == Enum.KeyCode.LeftShift then
			sprinting = false
			hum.WalkSpeed = 12

	if firstperson == false and input.KeyCode == Enum.KeyCode.C and not processed then
		firstperson = true		
		player.CameraMode = Enum.CameraMode.LockFirstPerson

		elseif firstperson == true and input.KeyCode == Enum.KeyCode.C and not processed then

			player.CameraMode = Enum.CameraMode.Classic

			firstperson = false

	if firstperson == true then
		local runService = game:GetService('RunService')
		local char = script.Parent
		local function updateShake()
			local currentTime = tick()
			if hum.MoveDirection.Magnitude > 0 then
				if sprinting == true then
					local bobbleX = math.cos(currentTime * 10) * 1
					local bobbleY = math.abs(math.sin(currentTime * 10)) * 1
					local bobble =, bobbleY, 0)
					hum.CameraOffset = hum.CameraOffset:lerp(bobble, .25)
				elseif sprinting == false then
					local bobbleX = math.cos(currentTime * 7) * .5
					local bobbleY = math.abs(math.sin(currentTime * 7)) * .5
					local bobble =, bobbleY, 0)

					hum.CameraOffset = hum.CameraOffset:lerp(bobble, .25)
				hum.CameraOffset = hum.CameraOffset * .75

I already have the “firstperson” variable that does exactly what you describe. What I’m having problems with is that when I go in first person and back out, the camera shake continues.

Oh sorry that time i did not read it carefully enough and now i think i know what is wrong with the script. Simply once


Starts running it will not look at the condition and execute updateShake every renderstepped.
As it does not look at firstperson variable at all inside the function.

You should simply add an if statement with firstperson variable IN the updateShake function.