Stamina depleted

Whenever my power is 0 and holding shift the camera bugs out, I also want to make it so when power is 0 you have to wait 2 seconds. How would I do this?

Heres my code:

function UpdateBarSize()

	Bar.Size = UDim2.fromScale(Power * .1, 1)
end

function StartRun()

	Tween1:Play()
	Humanoid.WalkSpeed = Run
		Power -= .03
		end

function StartWalk()

	Tween2:Play()
	Humanoid.WalkSpeed = Walk
	Power += .01
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

When your power reaches 0 while sprinting, the script calls StartWalk. Since this function adds to your power, it is no longer 0. The next time the while true loop repeats, it calls the StartRun function. Calling these two functions nearby relating to time causes the camera issues.

I would recommend switching sprinting to false when you reach 0 power while sprinting. This way, the camera issue isn’t as bad.

Also, what do you mean by waiting 2 seconds? Do you mean waiting 2 seconds before regenerating power?

Waiting 2 seconds when power is depleted

That still doesn’t give me much details, but you can do this:

if power <= 0 then
    task.wait(2)
end