Camera is glitching out

Whenever stamina reaches 0 the camera starts to bug out. Please help!
Here’s my code:

function StartRun()
	sprinting = true
	Tween2:Pause()
	Tween1:Play()
	Humanoid.WalkSpeed = Run
		Power -= .03
		end

function StartWalk()
	if Power < 10 then
		sprinting = false
		Tween1:Pause()
		Tween2:Play()
	Humanoid.WalkSpeed = Walk
		Power += .01
	end
end

function InputBegan(Input: Enum.KeyCode, gpe: boolean)

	if Input.KeyCode ~= Key or gpe or Sprinting then return end

	Sprinting = true
end

function InputEnded(Input: Enum.KeyCode, gpe: boolean)

	if Input.KeyCode ~= Key or gpe then return end

	Sprinting = false
end

UIS.InputBegan:Connect(InputBegan)
UIS.InputEnded:Connect(InputEnded)

while true do
	if Sprinting then

		if Humanoid.MoveDirection.Magnitude > 0 and Power > 0 then

			StartRun()
		else

			StartWalk()
		end

	elseif not Sprinting and Power < 10 then

		StartWalk()
	end

	UpdateBarSize()
	task.wait()
end
1 Like

(I couldn’t get anything to work for this problem)

Where is the part where the camera is changed? What are Tween1 and Tween2?

This is a stamina script. Tween1 zooms in the camera and tween2 zooms out the camera.

1 Like

It could be because in the while loop, StartRun and StartWalk are being called every time the loop runs so it keeps on tweening the camera’s field of view causing the jittering

How would I fix this issue exactly?

1 Like

Not sure right now but tomorrow I might be able to come up with something to fix this

Are you able to send the entire script including all the variables so I can have a better look?

Sorry for taking so long to respond, I had things to do but, you can try to create a variable that states whether or not the player is currently walking, then when the variable is changed, you can tween the camera’s FoV

1 Like