Wait for Minimum Players Not Working

In my code, I wait until there are a certain number of players and then it should continue with the rest of the script. But that isn’t working for some reason. This is my code:

local Players = game.Players:GetPlayers()
while wait() do
	if #Players >= minimumPlayers then
		print("Minimum players achieved")
		break
	else
		print("Waiting for 2 players")
		Status.Value = "Not enough players to start the game.."
	end
end

I’ve tried printing it but it always prints “Waiting for 2 players”. Oh and I forgot to say that minimumPlayers is set to 2.

1 Like

Well, you’re never updating the players value. It’s a constant value meaning it’ll always be the same. You’ll have to update it in the loop.

To be exact, you can just move the Players variable down into the loop.

1 Like

Are you talking about this bit local Players = game.Players:GetPlayers()?

1 Like

Yeah, that’s the variable I’m talking about.

Oh, I never knew that, I just thought it would automatically update. :man_shrugging:

Nope, cause it returns a table it wouldn’t automatically update.