Round system feedback

I am currently working on a round system. Does everything look right to you?

while true do
gameStatus.Value = "Waiting For Players"
repeat until game.Players.NumPlayers >= 2

if game.Players.NumPlayers >= 2 then
	gameStatus.Value = "Intermission"
end

wait(10)

local AvailableMaps = Maps:GetChildren()
local ChosenMap = AvailableMaps[math.random(1, #AvailableMaps)]

gameStatus.Value = "Loading Map"

wait(2)

local ClonedMap = ChosenMap:Clone()
ClonedMap.Parent = workspace


local spawnPointsFolder = ClonedMap:FindFirstChild("SpawnPoints")

local SpawnPoints = spawnPointsFolder:GetChildren()


-- teleporting
for i, player in pairs(plrs) do
	if player then
		character = player.Character
		
		if character then
			character:FindFirstChild("HumanoidRootPart").CFrame = SpawnPoints[1].CFrame
			table.remove(SpawnPoints, 1)
			
		else
			if not player then
				table.remove(plrs, 1)
			end
		end
	end
end
-- assinging player roles
	local AIndex = math.random(1, #plrs)
	local AIndex = plrs[AIndex]
	roach.Character:SetAttribute("A", true)

	table.remove(plrs, AIndex)

	local IIndex = math.random(1, #plrs)
	local Inspector = plrs[IIndex]
	Inspector.Character:SetAttribute("IIndex", true)

	table.remove(plrs, IIndex)
	
	for i, a in pairs(plrs) do
		a.Character:SetAttribute("a", true)
		
	end
end

Overall not too bad.

I just have a few tiny suggestions

  • Use task.wait() instead of wait() as I believe its a little more efficient.
  • Change the loop at the top to this
gameStatus.Value = "Waiting For Players"
repeat task.wait() until game.Players.NumPlayers >= 2
  • You should replace the “else” at the in the for loop with an
elseif not player then
    table.remove(plrs,1)

Thank you so much! I am experiencing one problem though. Whenever I start the game, “waiting for players” is not in the textlabel.

while true do
gameStatus.Value = "Waiting For Players"
repeat task.wait() until game.Players.NumPlayers >= 2
gameStatus.Value = "Intermission"

wait(10)

local plrs = {}

Here is the code that control the TextLabel:

local GameStatus = game:GetService("ReplicatedStorage").GameData:WaitForChild("GameStatus")
local Text = script.Parent

GameStatus.Changed:Connect(function()
	Text.Text = GameStatus.Value
end)

Try removing the “while true do” at the very top of the script, as that is not necessary anymore and may be the cause of the problem.

Yes but the while true do loops everything so there can be multiple rounds

#help-and-feedback:code-review

Sorry, I misread the code and didn’t realize the while true loop was the entire thing. I don’t recommend doing that because your code is constantly repeating everything including your variable definitions and it wont be very efficient and it may be the cause of the problem. I recommend using functions for better organization.