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

Loop wont break and i have no idea why. am i missing something about using break?

Asked by
abrobot 44
3 years ago
Edited 3 years ago

this is my basic script structure

local Module = {}



function Module.Function()

    local function LocalFunction()
        while true do
            wait(.1)
            if value is true then
                print("exp") -- this will print meaning the if condition was met but
                break -- this don't break
            end
            print("loop still running") -- this keeps printing after it should have broke
        end
    end

    LocalFunction()
end




return Module
0
what is "value is"? ForeverBrown 356 — 3y

3 answers

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Dude, it goes on forever because "while TRUEEEEEE do". Just put a boolean variable replacing true.

0
Oh i thought if i broke out of the loop the thread would end and it wouldnt run again abrobot 44 — 3y
0
did u check it though? huntergamind 2 — 3y
0
yes you were right i guess i just misunderstood how the while true do would react, thank you vary much abrobot 44 — 3y
Ad
Log in to vote
0
Answered by
Lakodex 711 Moderation Voter
3 years ago

Huntergamind is 100% wrong, since you put "if value is<<(This does not exist) true then". It caused an error

It's "if value == true then"

while true do
    if value == true then
        print("exp")
        break
    end
end
0
he was right its just in my exp i forgot to put two =s abrobot 44 — 3y
Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Normally when using while loops I don't use breaks to stop them. I would use a variable in place of "true." Looking something like this(just copying your code and changing it)...

local Module = {}

function Module.Function()
    --removed the local function because you did not need it for what you had going
    while variable == false do--will run this loop until the variable is set to true
        --run code
            wait(.1)
        end
end




return Module

As with your code, I am not sure what "value is" is referencing. When making variables they need to be one word. The break is never run in your code because the value is never set to true.

Answer this question