While loop doesn't work

I have this script:

while task.wait(1) do
	-- Destroying map after the code has been scanned
	-- Placing a new one for another round
	-- Destroying
	if PickedMap then
		local Values = PickedMap.Values
		PlayersValue = Values.Players
		CodeScanned = Values.CodeScanned
	if CodeScanned and PlayersValue then
		if CodeScanned.Value == true and PlayersValue.Value == 0 then

And while being set on the server, the CodeScanned value being true and the PlayersValue value being to 0, "true" doesn’t print. What should I do?

1 Like

You could try using the debugger to step through your code line-by-line and check that the values are what you expect.

That sadly doesn’t help.

Check if it’s even running.
Check if ‘if PickedMap then’ gets run. if it doesn’t, it won’t get through the second if statements as well.
Check if it gets through the second ones, maybe even remove the second if statement entirely, because if an object doesn’t exist, roblox will immediatly error and stop the thread.

don’t be afraid to spam the living crap out of if statements.

The most simple check you can do is print(CodeScanned.Value, PlayersValue.Value) and see if they are the values you are asking them to be.




Anyway I think I have found the problem, the Start() function has a task.wait(), plus with the loop’s one, so I’d say that there is a problem there. I thought while loops work like coroutines, but what can you do… Anyway, thanks for your help! I actually wrapped that 2 seconds ago.