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.