im trying to make a stamina system with a textlabel and im SO bad at scripting 😭
and when i release the sprint button i dont get +1 stamina every 0.5 secs, i get 100 stam instantly and i have no idea why it doesnt work, but i need help.
script:
local uis = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local stam = 100
local qHold = true
local label = player:WaitForChild("PlayerGui"):WaitForChild("speed"):WaitForChild("TextLabel")
local refilling = false
local function refillstamina()
if qHold == false and stam < 100 then
refilling = true
if refilling then
repeat
stam = stam + 1
wait(0.5)
until
stam == 100 or qHold == true
end
if stam == 100 then
refilling = false
end
end
label.Text = stam.."/100"
end
uis.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q then
qHold = true
if qHold == true then
humanoid.WalkSpeed = 30
if humanoid.WalkSpeed == 30 then
for i = stam, 0, -1 do
if not qHold then break end
label.Text = i.." /100"
wait(0.1)
if i == 0 then
humanoid.WalkSpeed = 16
wait(2)
for i = 0 ,100 +1 do
label.Text = i.." /100"
wait(0.2)
end
end
end
end
end
end
end)
uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q and qHold == true then
humanoid.WalkSpeed = 16
qHold = false
wait(1)
refillstamina()
end
end)
the problem is with the refillstamina.
** You are now Level 1! **