Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

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.

3 comments

0

If you don't understand, you can reply on the comment below. I will 'repeatedly' explain this 'until' you understand. :)

0

i thought i could accept both answers but i couldnt well i didnt think repeat loops were this complex

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

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

1 comment

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.