Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Stamina goes negative when I wrote code not to?

Asked by 2 years ago

My stamina script is going haywire, and I can't find my error so I can't learn from my mistakes, Can you guys help me?


RunService.RenderStepped:Connect(function() local maxstamina = 9 local StartingStamina = 0 print(timeyouahavebeenrunning) if Userinputservice:IsKeyDown(Enum.KeyCode.LeftShift) and humanoid.MoveDirection.Magnitude > 0 and Debounce == true then if timeyouahavebeenrunning >= maxstamina then local Debounce = false else humanoid.WalkSpeed = 23 camera.FieldOfView = 80 RunService.RenderStepped:Connect(RunningEffect) while wait(1) do timeyouahavebeenrunning = timeyouahavebeenrunning + 1 if timeyouahavebeenrunning >= maxstamina then break end end end else if timeyouahavebeenrunning <= StartingStamina then local Debouce = true else humanoid.WalkSpeed = 16 camera.FieldOfView = 70 RunService.RenderStepped:Connect(updateBobbleEffect) if timeyouahavebeenrunning < maxstamina then repeat wait(1) timeyouahavebeenrunning = timeyouahavebeenrunning - 1 until humanoid.MoveDirection.Magnitude > 0 and Userinputservice:IsKeyDown(Enum.KeyCode.LeftShift) if humanoid.MoveDirection.Magnitude > 0 and Userinputservice:IsKeyDown(Enum.KeyCode.LeftShift) then local Debounce = true end else while wait(1) do timeyouahavebeenrunning = timeyouahavebeenrunning - 1 if timeyouahavebeenrunning <= StartingStamina then local Debounce = true break end end end end end end)

1 answer

Log in to vote
0
Answered by 2 years ago

At lines 10, 26, 38, and 45, change "local Debounce" to "Debounce".

When you add local, it creates a local variable that only the current code block can change/read, therefore it doesn't change the Debounce used at line 6.

0
That did nothign cool_guy5121 3 — 2y
Ad

Answer this question