stamina script
local staminagui = script.Parent.staminaframe.stamina ----Your second frame that you made and scaled to x 1
local ui = game:GetService("UserInputService") ---With we can check what key did the player push down or let go
local playerrunning = false ---simple variable that we set
ui.InputBegan:Connect(function(key) ---when the player pushes any button this runs
if key.KeyCode == Enum.KeyCode.LeftShift then --if the button is leftshift, you can change it whatever you want to
playerrunning = true
end
end)
ui.InputEnded:Connect(function(key) --when the player let go any button
if key.KeyCode == Enum.KeyCode.LeftShift then
playerrunning = false
end
end)
local player = game.Players.LocalPlayer ---the player basically that the scripts is running for
local character = player.Character ---the player character model
local humanoid = character:WaitForChild("Humanoid") ---the humanoid in the player model
local runserivce = game:GetService("RunService") --- a service that let us to run a code in every frame
local stamina = 100 --maximum stamina
runserivce.RenderStepped:Connect(function() ---this code will run at every frame
local playermoving = humanoid.MoveDirection.Magnitude ---this checking if the player is moving, if its more than 0 then the player moving
if playerrunning == true and playermoving > 0 and stamina >= 0 then ---stamina reduce and walkspeed
humanoid.WalkSpeed = 32
stamina = stamina - 0.2
staminagui.Size = UDim2.new(stamina/100,staminagui.Size.X.Offset,staminagui.Size.Y.Scale,staminagui.Size.Y.Offset)
end
if playerrunning == false and stamina < 100 or stamina <= 0 then ---stamina recharge and walkspeed again
humanoid.WalkSpeed = 16
stamina = stamina + 0.2
staminagui.Size = UDim2.new(stamina/100,staminagui.Size.X.Offset,staminagui.Size.Y.Scale,staminagui.Size.Y.Offset)
end
if playerrunning == true and playermoving <= 0 or stamina <= 0 then ---stamina recharge and walkspeed again
humanoid.WalkSpeed = 16
stamina = stamina + 0.2
staminagui.Size = UDim2.new(stamina/100,staminagui.Size.X.Offset,staminagui.Size.Y.Scale,staminagui.Size.Y.Offset)
end
end)
Public Last updated: 2026-11-14 10:44:28 AM