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

Stamina Bar Will Not Budge In Size (or value?).

Asked by 5 years ago

This question has been solved by the original poster.

I have been trying to figure out how I can make a stamina bar that takes stamina away when sprinting. I can't understand what the problem is either, when I run it in game it has no errors even when I run, nothing. The bar seems to be glued to just one number like it keeps resetting it to the full value extremely fast, it might be the while loop but I honestly have no idea.

repeat wait() until game.Players.LocalPlayer.Character ~= nil
wait()

--Variables
local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humaniod = game.Players.LocalPlayer.Character:WaitForChild("Humanoid")
local Mouse = Player:GetMouse()
local Input = game:GetService("UserInputService")
local WASD = "w","a","s","d"
local Sprinting = false
local Stamina = 100
local Timer = 1.2

game.Players.LocalPlayer.Character.Humanoid.WalkSpeed = 10

--Key Detection
Input.InputBegan:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftControl then
        Sprinting = true
    end
end)

Input.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.LeftControl then
        Sprinting = false
    end
end)

--Stamina
if Humaniod.Running then
    if true then
        wait(0.5)
        Stamina = Stamina - 1
    end
    if Sprinting then
        wait(0.05)
        Stamina = Stamina - 1
    end
end

--Bar Fill
while true do
    Timer = Timer - 0.05
    script.Parent:TweenSize(UDim2.new(Stamina/100,0,0.167,0), Enum.EasingDirection.In, Enum.EasingStyle.Linear, 0.5)
    if Humaniod.Running == false then
        Timer = 1.2
    end
    if Stamina < 0 then
        Stamina = 0
    elseif Stamina > 100 then
        Stamina = 100
    end
    if Timer < 0 and Stamina > 100 and Humaniod.Running == false then
        Stamina = Stamina + 2
        wait(0.1)
    end
    wait(0.05)
end

Any help would be appreciated.

0
ur waiting 1/20 of a second.... EmbeddedHorror 299 — 5y
0
u have the tween as 0.5 sec then ur looping every 1/20 th EmbeddedHorror 299 — 5y
0
I do not understand? Can you please elaborate? masterhunter0114 0 — 5y
0
Oh, I think I get it. Thank you sir. masterhunter0114 0 — 5y
0
Yeah, I figured it out thanks to usernamewitheld. I was using wait(0.05) when the tween was only going 0.5 speed. The loop was restarting too fast for the bar to catch up. masterhunter0114 0 — 5y

Answer this question