Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

While loop not working but while true loop does?

Asked by 4 years ago

Why does this not work:

while itemName.Value ~= "none" do
    wait(.0001)
    print("item value is not none")
    gui.Visible = true
    gui.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
end

While this does:

while true do
    wait(.0001)
    if itemName.Value ~= "none" then
        gui.Visible = true
        gui.Position = UDim2.new(0, mouse.X, 0, mouse.Y)
    end
end
0
forgot to mention i've set this to run when it does not equal to "none" and on default it is something else. bopperhead 2 — 4y

2 answers

Log in to vote
0
Answered by 4 years ago

The second script will keep looping regardless wether (itemName.Value ~= "None") results in true or false

Since the condition for the while loop will always be true

The first script however use (itemName.Value ~= "none") as its condition, which means once (itemName.Value ~= "none") resulted in false, the script will stop running

Ad
Log in to vote
0
Answered by 4 years ago

Because the conditional is not true

Answer this question