How update stamina? code issues

Hello! I have tried everything and I can not update the stamina …
could someone help me? Please

I would like to make the stamina increase up to 100 at all times that it is less than 100 and greater than 0, how can I do it?

  local Stamina = 100
  local Players = game:GetService("Players")

    Players.PlayerAdded:Connect(function(player)
    	print(player.Name .. " joined the game!")
    	if Stamina >0 and Stamina > 100 then
    		print("Updating stamina + 5")
    		Stamina = Stamina + 5
    	end
    end)

st1

st2

st3

your if statement is the problem

why? how could i fix that? :open_mouth:

is 100 greater than 0? Sure but we are saying and meaning they both need to be true. Is 100 greater than 100? It is equal to it but not greater.

use a less-than symbol < when checking if your Stamina is less than 100.

if Stamina > 0 and Stamina < 100 then
    
end

This code is fine so that the player’s life is updated every time it goes down? :open_mouth: it didnt worked

Are you trying to make a system where a player can sprint if they have enough stamina, the stamina regenerates over time, and will constantly update the UI element with the amount of stamina they have?

1 Like

Yes! Yes! Exactly that, Could you help me with that please :frowning:

I built a simple sprinting-with-stamina system for you. Here is the place file:
SprintingSystem.rbxl (24.9 KB)

You can take all the source code/objects from the place file and move them into your original project. There is:

  • ToggleSprint RemoteEvent (belongs in ReplicatedStorage)
  • StaminaGui ScreenGui (belongs in StarterGui)
  • ServerSprint ServerScript (belongs in StarterPlayer > StarterCharacterScripts)
  • ClientSprint LocalScript (belongs in StarterPlayer > StarterPlayerScripts)

The system lets you sprint using LeftShift or RightShift, only lets you sprint if you have enough stamina, and regenerates stamina over time. There is also a stamina Gui that shows how much stamina your player has at all times.

Let me know if you have any issues.

2 Likes

Wow thank you very much! I really appreciate it a lot, I will implement it in my project. :heart_eyes:

1 Like