I’m trying to get this code to be a perfect loop of a lobby-game-lobby, but for some reason it doesn’t loop correctly.
I’ve tried rearranging some code but it never worked.
Everything that is defined is correct, no errors in the developer console.
Here’s the code:
while true do
game.Teams.Lobby.AutoAssignable = true
game.Teams.Bravo.AutoAssignable = false
game.Teams.Foxtrot.AutoAssignable = false
local lobby = game.ReplicatedStorage.LobbyMap:Clone()
lobby.Parent = workspace
workspace.LobbyMusic.Playing = true
for _, v in pairs(game.Players:GetChildren()) do
if v:IsA("Player") then
v.Team = game.Teams.Lobby
wait()
local i = v.Backpack:FindFirstChildOfClass("Tool")
v.i:Destroy()
if v.Character:FindFirstChildOfClass("Tool") then
v.Character:FindFirstChildOfClass("Tool")
end
v.Character.Humanoid.Health = 0
end
end
if game.Workspace:FindFirstChild("Map") then
game.Workspace["Map"]:Destroy()
end
local m = Instance.new("Hint", workspace)
for i = 30,1,-1 do
m.Text = ("Game will start in: "..i)
wait(1)
end
if m.Text == "Game will end in: 1" then
wait(1)
m:Destroy()
end
Folder = game.ReplicatedStorage.Maps:GetChildren()
local rMap = Folder[math.random(1,#Folder)]:Clone()
m:Destroy()
local h = Instance.new("Message")
h.Parent = game.Workspace
h.Text = "The next map will be... "..rMap.Name.."!"
wait(2)
h:Remove()
workspace.LobbyMusic.Playing = false
rMap.Name = "Map"
rMap.Parent = game.Workspace
game.Teams.Lobby.AutoAssignable = false
game.Teams.Bravo.AutoAssignable = true
game.Teams.Foxtrot.AutoAssignable = true
local red = game.Teams.Bravo
local yellow = game.Teams.Foxtrot
local teams = {red, yellow}
for _, v in pairs(game.Players:GetPlayers()) do
if v:IsA("Player") then
wait()
v.Character.Humanoid.Health = 0
wait()
if #red:GetPlayers() > #yellow:GetPlayers() then
v.Team = yellow
elseif #red:GetPlayers() < #yellow:GetPlayers() then
v.Team = red
else
v.Team = teams[math.random(1, #teams)]
end
end
end
if game.Workspace:FindFirstChild("LobbyMap") then
game.Workspace["LobbyMap"]:Destroy()
end
local m2 = Instance.new("Hint", workspace)
for i = 300,1,-1 do
m2.Text = ("Game will end in: "..i)
wait(1)
end
if m2.Text == "Game will end in: 1" then
wait(1)
m2:Destroy()
end
end