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
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 = {}
local GameStatus = game:GetService("ReplicatedStorage").GameData:WaitForChild("GameStatus")
local Text = script.Parent
GameStatus.Changed:Connect(function()
Text.Text = GameStatus.Value
end)
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.