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

I have attempted to make a stamina system and for some reason it's random?

Asked by 2 years ago
Edited 2 years ago

I have attempted to make a stamina system but the problem is that whenever I start the game and look at the output it goes negative and in a second it'd be -1000 and whenever you start running it'd go up there is no part of the script that would do this

so that means the amount of time of running will take longer to deplete stamina if you don't run edit: if your wondering why I have renderstepped, there's code that is not part of the issue

local timeyouahavebeenrunning = 0
RunService.RenderStepped:Connect(function()
    local stamina = 6


    if timeyouahavebeenrunning == stamina then
        camera.FieldOfView = 68
        humanoid.WalkSpeed = 14
        wait(6)
        timeyouahavebeenrunning = timeyouahavebeenrunning - timeyouahavebeenrunning
    elseif Userinputservice:IsKeyDown(Enum.KeyCode.LeftShift) or Userinputservice:IsKeyDown(Enum.KeyCode.RightShift) then

            camera.FieldOfView = 80
            humanoid.WalkSpeed = 23

            repeat 

                timeyouahavebeenrunning = timeyouahavebeenrunning + 1
                wait(1)

            until timeyouahavebeenrunning == 6
        else
            camera.FieldOfView = 70

            humanoid.WalkSpeed = 16

            repeat 
                timeyouahavebeenrunning = timeyouahavebeenrunning - 1
                wait(1)

            until Userinputservice:IsKeyDown(Enum.KeyCode.LeftShift)or Userinputservice:IsKeyDown(Enum.KeyCode.RightShift) or timeyouahavebeenrunning == 0

            end
        end)


1 answer

Log in to vote
0
Answered by 2 years ago

You need to add debounce so it doesn't repeat the loop many times rather than waiting.

0
Either I did it wrong but didn't work, can you show me? cool_guy5121 3 — 2y
0
Plus, the waiting is meant for how long you can run, I want to run for 6 seconds cool_guy5121 3 — 2y
Ad

Answer this question