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 3 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?

01RunService.RenderStepped:Connect(function()
02    local maxstamina = 9
03    local StartingStamina = 0
04 
05    print(timeyouahavebeenrunning)
06    if Userinputservice:IsKeyDown(Enum.KeyCode.LeftShift) and humanoid.MoveDirection.Magnitude > 0  and Debounce == true then
07 
08 
09        if  timeyouahavebeenrunning >= maxstamina then
10                local Debounce = false
11        else
12            humanoid.WalkSpeed = 23
13            camera.FieldOfView = 80
14            RunService.RenderStepped:Connect(RunningEffect)
15            while wait(1) do
View all 55 lines...

1 answer

Log in to vote
0
Answered by 3 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 — 3y
Ad

Answer this question