I'm trying to build a stamina bar GUI for my game. I already built a Health Gui from AlvinBlox's youtube channel. Don't worry i tried to understand about the guis. I started thinking how to start scripting. I tried setting an IntValue to stamina. Such as 100. And then i told the script: if the player's walkspeed is above 16 then substract 1 from the so-called 'STAMINA POINTS' each second. Here's what my code sort of looked like. Am I going the right way? I used a local script. What else could I use?
local player = game.Players.LocalPlayer
local humanoid = player.Character.Humanoid --------------------- HUMANOID?
local staminabar = script.Parent -------------------------THE ACTUAL STAMINA BAR
local staminaframe = script.Parent.Parent ---------------------FRAME THAT HOLD THE BAR
local staminamax = 100 ----------------------------MAXIMUM STAMINA
humanoid.Changed:connect(function()
local stamina = Instance.new('IntValue', player)
stamina.Name = 'StaminaVal'
stamina.Value = 100
while true do
if humanoid.WalkSpeed > 16 then ------------if walkspeed > 16 then waste stamina
stamina.Value = stamina.Value - 1
wait(1)
end
end
script.Parent.Size = UDim2.new(stamina.Value/staminamax,0,1,0)
end)

4 comments
Well, it'll only work if the player's WalkSpeed value is greater than 16, and not when running/ walking/ etc.; if that's your intention, then I recommend using the Magnitude value of Velocity from the player's torso, which is a bit complicated & may be overdoing things. :P
I forgot to mention this, but i really only want to waste stamina when WalkSpeed is faster than 16. So long as its above 16 stamina decreases. Which is really boring. If you have any other suggestions on how i should use the stamina bar please let me know.
i ALSO FORGOT TO MENTION THAT IT DOESN`T WORK
whats the line after end for?