Looping infinity?

    while istime >= 0 or noplayer ~= 1 do
		istime -= 1
		if game.Workspace.AlreadyChecked.Value == true then
			game.Workspace.AlreadyChecked.Value = false
			game.Workspace.ClearedPerson.Value = 0
		end
		wait(1)
		for _, team in pairs(teams) do
		    local players = team:GetPlayers()
			if team.Name == "Game" then
				if #players == 0 then
					noplayer = 1
					print(noplayer) -- debugging
					wait(3)
					break
				end
			end
		end
	end

Is there anything wrong on this while loop?

Line 2, -= is not a mathematical operator in Lua. You do istime = istime - 1 to achieve this.

that is not at all true, this is a luau type of scripting which roblox has recently added.

It looks alright, but it all just depends on first, how large the istime variable is (it’s not shown in your script), and second, if the noplayer variable is getting changed correctly.

With that print(noplayer) that you did for debugging, did it print?

So it seems that the problem is with whether or not the conditions of the while loop are being met.

Also, try changing that section you gave us of the script to this (added prints) to see what istime is equal to as it prints. Here:

    while istime >= 0 or noplayer ~= 1 do
		istime -= 1
        print(istime) -- debugging

		if game.Workspace.AlreadyChecked.Value == true then
			game.Workspace.AlreadyChecked.Value = false
			game.Workspace.ClearedPerson.Value = 0
		end
		wait(1)
		for _, team in pairs(teams) do
		    local players = team:GetPlayers()
			if team.Name == "Game" then
				if #players == 0 then
					noplayer = 1
					print(noplayer) -- debugging
					wait(3)
					break
				end
			end
		end
	end

Well no, it’s a compound operator quite recently added to roblox lua.

Oh I didn’t realize they added -= with Luau, that’s cool.

2 Likes

Here, take a look: Luau Recap: June 2020

did you check in an if statement that the time value is more then 0 or less then 1

Right here he checks it with the while loop.

i get your error it only breaks the for loop not the while loop so if the for loop is done break the while loop

istime variable value is 240, it is printing like this

239
238
237
236
235
...

however, if conditional has operated it prints -1.

well after the for loop you can add an if statement if the time is less then 0 then break it

Isn’t that how it’s supposed to work? Take a look.

Right here you say if it’s equal to or greater than 0 then make istime itself minus one. So when istime hits 0, it will subtract 1 from istime and run that one last time. Thus, you get istime being equal to -1.

If you don’t want it to say -1, then just do while istime > 0 instead.

2 Likes