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)
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?
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.