.Changed in a loop

I have a game loop which starts and ends rounds etc and ends rounds based on a timer which was ticking down which looks like:

if #plrs == 0 then
			Status.Value = ""
			break                                    
		elseif i == 0 and game.ServerStorage.team1points > game.ServerStorage.team2points then 
		Status.Value = "Team 1 wins" 
		break	
		elseif i == 0 and game.ServerStorage.team1points < game.ServerStorage.team2points then 
		Status.Value = "Team 2 wins"		
		break

however I want to be able to also end the rounds based on x team reaching x amonut of points, so I set up another script which follows the value of both teams points and once one reaches the x amount of points it changes a string value to the winning team.

So now I need to be able to check this value so when it gets changed the main script can follow and end the round however having a .Changed function would break the loop and putting the loop inside the .Changed function breaks a few global variables so im wondering what the best way to do this would be.

Ideally this is how it would look following on from the previous lines of code:

elseif val == "a" then
		Status.Value = "Team 1 wins!"
		break
elseif val == "b" then
		Status.Value = "Team 2 wins!"
		break
		end

With val being the stringvalue in storage which gets changed to the winning team

Why would a .Changed event broke a loop?

Adding line 214 (the .changed) cuts it off from the rest of the loop (while true do loop)

You did not type the event correctly. Or is the if inside the event?

This is all inside the loop and the .Changed

Usually you don’t want .Changed connections inside a loop. Also you can delete the break if it is inside an event, since the ifs stop there.

thats why im looking for another way to get the updated value within the loop, I need the breaks since the script doesnt end there

Well as the loop runs check for the value. There isn’t any other way to do this AFAIK

2 Likes