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

How would I approach making a stamina bar?

Asked by 4 years ago

Hi, I'm fairly new to scripting although I know many of the basics. I'd like to create a stamina bar for sprinting. I've figured I'll probably have to use a remote event to stop it from being exploited, but not entirely sure how I'd approach making this. I know how to create the shift to sprint and GUI, it's just the stamina bar depletion/regain (out of 100%) I'm not sure how I'd approach, any help and suggestions would be appreciated.

0
Do a while loop which checks if your run button is held down. If it is up, it loops up, otherwise, it loops down. Thepoint13 99 — 4y
0
Yes however this doesn't really solve the issue of the client exploiting it, say if I had a value in the local script as 'stamina', it could probably be exploited to stay above 0. Would I perhaps have to create an intvalue in the server as the players name and raise/lower this depending on if they're sprinting or would this be overthinking it? Shrilleh 68 — 4y
0
Just detect and edit the value on the server so local scripts are not able to configure it? Prestory 1395 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

There are many good tutorials on YouTube for like like this one or this one.

The code below isn't really copy-paste-able, it's just an example.

How to start:

game.Workspace.Player.Humanoid.Running:connect(function(speed)
    if speed > 16 then
        print("Player is running")
    -- decrease stamina bar
    elseif speed == 16
        print("Player is walking")
    -- increase stamina bar
    elseif speed == 0
    print("Player stopped")
    end
end)

The GUI

You could then take bits from tutorials like this and this to help you make the GUI.

That's how you can start.

Ad

Answer this question