Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I approach making a stamina bar?

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.

3 comments

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.

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?

0

Just detect and edit the value on the server so local scripts are not able to configure it?

1 answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.