How to create a round system?

Hello,

So I was just wondering what is the best way of creating a round system. I have a basic idea in that you do a while true loop but I can’t seem to be able to think of a good way checking if the server still has the correct amount of players or not. I could do if statements in ever section but the issue with this is that I would be having loads of if statements doing the same thing so I was wondering if anyone had a better idea of how to do this.

1 Like

This was the best I found which was structured in a neat way:

My adaptation on the method into OOP here:

1 Like

So I had a quick read but I don’t see how this would fix my issue of checking if the server player count meets the required count. Also I don’t think is would work very well for what I am looking for because I want stuff to happen during the game period not just waiting until the end.

Maybe something like:

while task.wait(1) do
if #game.Players:GetChildren() > REQUIRED_PLAYERS then
--Round script
else --Not enough players :(
end

It won’t have too much of an impact of performance if any so yeah. :+1:

I mean first of all you should not have a wait in the while loop but also yea that works for the first time but when the game is playing there is no way for it to check if the count still meets the required players.

You can use a ‘for’ loop that acts as the timer and checker while the game goes on.

local RequiredPlayers = 2
local RoundDuration = 500
while task.wait(1) do
  if #game.Players:GetChildren() >= RequiredPlayers then
    for i = 1, 500 do
      print(i) --Time left
      if #game.Players:GetChildren() < RequiredPlayers then
      break
  end
  else --Not enough players :(
end

Yea well that was my idea but that would result in checking it lots of times which is not that bad but still I feel there could be a better way.

I use that version because my game has a clock displaying the time.
True, there are better ways, such as checking for the :ChildRemoved() event in players.
But it’ll take a bit longer to script since you have to relay it to the round system loop.