#stamina script error

1 messages · Page 1 of 1 (latest)

proven trout
#

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.

burnt trench
#

remove the if statements theres too many

#

use task.wait and use capital letters for variables

frank hamlet
#

maybe put the " label.Text = stam.."/100" " inside the repeat so the text is updated every 0.5 seconds and use task.wait

#

instead of wait

#

and get rid of some of your nests people tend to help more when you have less nests

proven trout
#

thx

frank hamlet
#

so did it work?

proven trout
#

no im trying now

fallen eagleBOT
#

studio** You are now Level 1! **studio

frank hamlet
#

ah i see

#

gl

proven trout
#

thx

proven trout
#

my only problem is that it literally doesnt add +1 to stam idk why

burnt trench
#

send ur code again u had until 100 and stam is already 100

#

stam doesnt get updated cause the if check where it gets updated doesnt pass

#

gest to the refilling if check and fails cause stam is already 100 and qHold is true anyways if refilling then
repeat
stam = stam + 1
wait(0.5)
until
stam == 100 or qHold == true
end

proven trout
#

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
while Refilling do
repeat
Stam = Stam + 1
Label.Text = Stam.." /100"
task.wait(0.5)
until
Stam == 100 or qHold == true
end
if Stam == 100 then
Refilling = false
end
end
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"
task.wait(0.1)
while i == 0 do
humanoid.WalkSpeed = 16
task.wait(2)
for i = 0 ,100 +1 do
Label.Text = i.." /100"
task.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
task.wait(1)
RefillStamina()
end
end)
here

burnt trench
#

whats the point of the refilling variable

#

it doesnt do anything

#

do the previous advice too

proven trout
#

ok

proven trout
burnt trench
#

Stam = 100

while Refilling do
repeat
Stam = Stam + 1
Label.Text = Stam.." /100"
task.wait(0.5)
until
Stam == 100 or qHold == true
end

#

qHold is true too so it doesnt do this code

proven trout
#

oh ok

#

uis.InputEnded:Connect(function(input)
if input.KeyCode == Enum.KeyCode.Q and qHold == true then
humanoid.WalkSpeed = 16
qHold = false
task.wait(1)
RefillStamina()
end
end)
but this makes qHold false so um

burnt trench
#

yeah but it doesnt update Stam you said

proven trout
#

wdym

burnt trench
proven trout
#

idk why it doesnt get updated

burnt trench
#

clear ur code first then u can think about that

#
repeat
    print(Stam)
    Stam = Stam + 1
    task.wait(0.5)
until Stam == 100```
this works for me so the if check for you doesnt work
#

if qHold == false and Stam <= 100 then
replace it with this

#

local Stam = 100

if Stam <= 100 then
repeat
print(Stam)
Stam = Stam + 1
task.wait(0.5)
until Stam == 100
end

this updates Stam so its just the logical operator

#

i dont know why the until doesnt do anything but alright

fallen eagleBOT
#

studio** You are now Level 12! **studio

burnt trench
#

if you need that to work you shouldnt use repeat and just use a for loop

proven trout