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

why wont BoolValue in workspace change to true?[Solved]

Asked by 3 years ago
Edited 3 years ago

nothing complex just something simple

local Value = workspace.Boolvalue
if Value.Value == false then    
    repeat      
        print("1")      
        wait()      
    until Value.Value == true
end
wait(5)
Value.Value = true

my main issue is that the value legit wont change to true and i dont know whats causing it because these lines of code makes too much sense to me so it confuses me when it didnt work and the print just kept going

Note: this is a Server Script that im using in server script service

3 answers

Log in to vote
0
Answered by
Ludzik78 136
3 years ago

Its because your repeating it until the value is true right? Repeat works that it doesnt pass itself until something. This is a bit of a complex code but i put comments so its easier to understand

local Value = workspace.Boolvalue --Gets the boolvalue, as expected
local count = 1 --This will count to 5
repeat
    print(count) -- Prints count
    count = count + 1 --Adds 1 to count
    if count == 5 then -- Checks if count = 5
        print("Got the number 5! Setting bool to true..")
        Value.Value = true
    end
    wait(1)
until Value.Value == true

print("Hello, im done with my loop!") --next code
Ad
Log in to vote
0
Answered by
Xapelize 2658 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

Ok. If you need to explain this in baby terms, let's think about that, loop are a "roadblock".

On Lua, you gotta run the code from the top, to the downest, right? But, the repeat loop "blocked" the route from the top, to the downest.

Let's see a sample like this:

x = 1
repeat
    print("1 plus 1 is not 3!")
    wait(1)
until 1 + 1 == 3
x = 2

So, if you executed the script, it will show full of printed text as "1 plus 1 is not 3!". Well, it's because it is on a loop, it will only pass when 1 plus 1 equals to 3, which is definitely impossible in mathematics terms.

But, what about the x value? Well, the repeat loop "blocked" the route from up, to down. So the x value is always 1, but not 2.

Your problem is pretty much alike. The Lua code cannot pass the repeat loop since the Value's value is never going to be true, because of the "roadblock" where I mentioned before. Instead, you can make a possible roadblock, like a repeat loop made timer, if the time is at a specific value, the Lua pass over the repeat loop roadblock and continuing the rest of the code.

Please note, scripts do not need to be put as a ServerScript. Normally, we would just use 2 scripts, Script or LocalScript. Also, do not put LocalScript into Game.ServerScriptService, it won't work.

0
If you don't understand, you can reply on the comment below. I will 'repeatedly' explain this 'until' you understand. :) Xapelize 2658 — 3y
0
i thought i could accept both answers but i couldnt well i didnt think repeat loops were this complex proROBLOXkiller5 112 — 3y
0
i think i understood this pretty well so basically i just have to put code in between repeat and until to stop the loop proROBLOXkiller5 112 — 3y
Log in to vote
0
Answered by 3 years ago

i think i pretty much got it. i was doing something that would work on a while true do loop but wouldnt on a repeat until loop

0
while true do loop are unpassable, except using break. Using an repeat loop is better except you want the loop to yield it forever. Xapelize 2658 — 3y

Answer this question