How to make a round end once a certain amount of players reaches the finish line

Making a game that starts out with like 30 players and each round is a new obby that players must complete before a certain amount of players. So like if the game starts with 30 players the first round can only have 25 winners then the next round 20 ect. until there is one winner. I also added a timer just in case it takes the players an extra long time to finish. There is no issue with the timer but, the issue I have is that I made a number value in serverscriptstorage and everytime a player reaches the end the number value goes up so how can I make the timer script stop (Which is a local script) once the max player is reached.

while roundtime ~= 0 do
		Timer.Text = "Time Left : "..roundtime
		roundtime = roundtime - 1
		wait(1)
	end

This is the code that runs the timer in a local script. It changes the text of a screen GUI on the screen that shows how much time is left.

Make an if-statement in your loop. If the number value is greater or equal to 25, then stop the loop using break.

Let’s say you had a number representing the number of players that have reached the finish line. You want to stop the round once enough players have reached the finish line.

local playersFinished = 0
local roundTime = 60
local interval = 1
while roundTime > 0 do
    roundTime -= interval
    if playersFinished >= 25 then
        break
    end
    task.wait(interval)
end

The issue is that this is a local script so if another player reaches the finish line how will I increase the variable that is in a local players script.

When making round systems, you have to implement this system in the server so it replicates for ALL players. Doing it on the client makes the system more susceptible to exploits, and it also ruins the sync between all players.

However, to replicate this to all players from one player reaching the finish, you would have to make use of RemoteEvents and/or RemoteFunctions. A RemoteEvent would get fired from the player that reached the finish line, send it to the server, the server would take in the signal and send a signal to all other players, then the players would add the value to the value their local script has.

Yea the system is on the server, the local script is just to show the GUI, I get what you mean with remote events but this is the full function I made

StartGame.OnClientEvent:Connect(function(roundtime, round)
	Timer.Parent.Enabled = true
	SpotsLeft.Parent.Enabled = true
	Timer.Text = "Time Left : "..roundtime
	local max = 30 - (round * 5)
	local taken = 0
	SpotsLeft.Text = "Spots Taken : "..taken.." / "..max
	while roundtime ~= 0 do
		Timer.Text = "Time Left : "..roundtime
		roundtime = roundtime - 1
		wait(1)
	end
end)

taken is a variable I made for how many players have made it to the end. I don’t think I can use remote functions to change this variable because it is inside of a function