Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I have made a Stamina Bar. How do you make it decrease vertically?

Asked by 3 years ago
Edited 3 years ago

Ok, so I have made a Stamina bar in Roblox Studio and it works completely fine. However, I want it to decrease vertically when the player runs, but it decreases horizontally when the player runs.

Anyway here is my script:

local bar = script.Parent

local stamina = 100
local staminaRate = 1


local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()

local humanoid = char:WaitForChild("Humanoid")


local isSprinting = false


local uis = game:GetService("UserInputService")


uis.InputBegan:Connect(function(key, gameProcessed)

    if gameProcessed or stamina == 0 then return end


    if key.KeyCode == Enum.KeyCode.LeftControl then

        isSprinting = not isSprinting

        if isSprinting then
            humanoid.WalkSpeed = 25
        else
            humanoid.WalkSpeed = 16
        end
    end
end)


while wait() do


    if stamina == 0 and isSprinting then

        isSprinting = false
        humanoid.WalkSpeed = 16
    end


    if isSprinting and humanoid.MoveDirection.Magnitude > 0 then

        stamina = stamina - 1
        wait(staminaRate)

    else
        stamina = stamina + 1
        wait(staminaRate)
    end


    stamina = math.clamp(stamina, 0, 100)

    bar:TweenSize(UDim2.new((1/100) * stamina, 0, 1 ,0), Enum.EasingDirection.InOut,                            Enum.EasingStyle.Quint, 0.5)
end
0
tl;dr. but on line 21 you change x, I suppose you wanna change the y. UDim2.new(1, 0, (1/100) * stamina ,0). maybe? noammao 294 — 3y
0
You should really read up on Udim2 before using it Spjureeedd 385 — 3y
0
Or just double check the code noammao 294 — 3y

Answer this question