Game cycle main script

Hi, I am trying to find out the best way to deal with a game cycle, and I think I might have unfounded concerns about using a loop.

This is a sample from the Roblox place “Capture the flag”, everything is run from the ServerScriptService code:


GameManager:Initialize()

while true do
	repeat
		GameManager:RunIntermission()
	until GameManager:GameReady()
	
	GameManager:StopIntermission()
	GameManager:StartRound()	
	
	repeat
		GameManager:Update()
		wait()
	until GameManager:RoundOver()
	
	GameManager:RoundCleanup()
end 

Functions within, trigger events from modules and overall seems like a pretty neat script.

Questions:

  • Is this the best way to handle a game cycle?
  • Does having this never ending loop affect game memory usage, processing power, is there anything that could be done to improve it?

Thank you in advance.

You could use events tho.
Dont worry about memory usage. Luau have an automatic garbage collector.
Also, as some wise man said " Make everything as simple as possible, but not simpler"

In terms of how well this follow any form of scripting architecture, it is probably one of the greatest for a template itself. Never-ending loops does have its slight memory leaks(if poorly executed) but those are barely noticeable until a longer session is done.

Maybe replace this with RunService.Stepped:Wait() if you have to. Otherwise I would wait longer since it is more efficient.