Easing Direction

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)

playerGui.PlayerStatus.BehindStam.Stamina.Size = UDim2.new(math.clamp(stam / maxStam, 0, 1), 0, 1, 0)

You are modifying the X-Scale right here, if you want to change it vertically, you need to modify the Y-Scale instead.

playerGui.PlayerStatus.BehindStam.Stamina.Size = UDim2.new(1, 0, math.clamp(stam / maxStam, 0, 1), 0)

If this is causing the bar to scale inwards on itself from both sides, change the anchor point for Y to be 0 or 1 and re-position the bar accordingly.

1 Like

great thank you that works. now i just need the stamina bar to start descending down to be empty instead of it ascending up to be empty

Change the anchor point to 1 on the Y-Axis and re-position the bar to where its located right now. It should scale downwards whenever the calculation is done.

1 Like