task.spawn(function()
while task.wait(1) do
if not char:GetAttribute(“Running”) then
print(“yoo”)
end
if stamina.Value < 100 then
print(“sup”)
end
end
end)
while not char:GetAttribute(“Running”) and stamina.Value < 100 do
print(“sup”)
task.wait(2)
if not char:GetAttribute(“Running”) and stamina.Value < 100 then
stamina.Value += 20
print(“hello”)
end
end
With a while loop, it will run until the condition is not met. If char:GetAttribute(“Running”) is false or stamina.Value is greater than or equal to 100, the loop will break out and continue to run code beneath. If you want this running consistently, you can do something like the following:
local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:Wait()
char:GetAttributeChangedSignal("Running"):Connect(function()
while char:GetAttribute("Running") do
task.wait(1)
stamina.Value -= 20
end
end)
what i mean is the top part is printing both “yoo” and “sup” suggestiing the conditions on the while loop below are met yet the “sup” inside of the while loop below is NOT printing meaning it is NOT running for some reason despite the conditions being met
Yes, the conditions aren’t originally met. The top loop waits a second and continuously checks, whether or not the conditions are true. The bottom runs instantly, and is the conditions are ever false, it will never run again.
why would it never run again? [char min]
That’s just how a while loop works; it runs while the conditions are met. Once they aren’t met, it stops running. You could switch it out with something like this if you would prefer:
while true do
task.wait(2)
if not char:GetAttribute(“Running”) and stamina.Value < 100 then
stamina.Value += 20
print("Hello")
end
end
Oh i didn’t realize it stopped running forever once the conditions werent met
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.