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

Is there a way to stop a "while,do" statement through an if statement?

I am trying to stop seconds from changing and set it to 0 once there are no more people inside of a team. Here is my code:

local seconds = game.ReplicatedStorage.Seconds
local Playing = game.Teams.Playing

	while seconds.Value > 0 do
		if #Playing > 0 then
		wait(1)
		seconds.Value = seconds.Value - 1
	end

Any suggestions?

4 comments

0

Wait, let me edit it...

1

just put the word break in the loop and it will break, make sure its at the end or in an if statement

0

^

0

edited my answer

1 answer

you could break the loop link

Example:

local secondsElapsed = 0
local timeout = 5
 
while true do
	print("Looping...")
	wait(1)
	secondsElapsed = secondsElapsed + 1
 
	if secondsElapsed == timeout then
		break
	end
end
 
print("Loop ended; moving on!")

For your script:

local seconds = game.ReplicatedStorage.Seconds
local Playing = game.Teams.Playing
while true do
    if #Playing > 0 then
        wait(1)
        seconds.Value = seconds.Value - 1
        if seconds.Value == 0 then
            break
        end
    end
end

2 comments

0

Thanks!

0

Edited.

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