I was making a stamina Bar system and i intentionally made it vertical instead of horizontal. So when the stamina would drain i want it to drain up to down, but i couldn’t figure out how to do that. I know this might be trivial but any help will do thank you
Here’s my code:
–{{ Services }}–
local UIS = game:GetService(“UserInputService”)
local RS = game:GetService(“RunService”)
–{{ Variables }}}–
– Player –
local player = game.Players.LocalPlayer
local character = player.Character or player.Character:Wait()
local hum = character:WaitForChild(“Humanoid”)
local playerGui = player.PlayerGui
– Settings -
local stam = 100
local maxStam = 100
local speedDif = 40
local DrainRate = 20
local refreshRae = 90
local stamRefresh = 0
– Booleans ==
local sprinting = false
local sprintingHeld = false
local exhausted = false
–{{ Function }}–
local function sprint(active)
if exhausted then return end
hum.WalkSpeed = active and hum.WalkSpeed + speedDif or hum.WalkSpeed - speedDif
sprinting = active
end
local function onInput(input)
if input.KeyCode == Enum.KeyCode.LeftControl and input.UserInputType ~= Enum.UserInputType.Gamepad1 then
sprintingHeld = input.UserInputState == Enum.UserInputState.Begin
sprint(sprintingHeld)
end
end
local function updateStaminaUI()
playerGui.PlayerStatus.BehindStam.Stamina.Size = UDim2.new(math.clamp(stam / maxStam, 0, 1), 0, 1, 0)
end
UIS.InputBegan:Connect(onInput)
UIS.InputEnded:Connect(onInput)
RS.Heartbeat:Connect(function(deltaTime)
if sprinting then
stam = math.max(0, stam - DrainRate * deltaTime)
updateStaminaUI()
print(math.floor(stam))
if stam == 0 then
sprint(false)
exhausted = true
end
else
stam = math.min(100, stam + refreshRae * deltaTime)
if stam >= stamRefresh then
updateStaminaUI()
exhausted = false
print(math.floor(stam))
if sprintingHeld then
sprint(true)
end
end
end
end)