Bugs for my Capture The Flag game

So I’m making a Capture the Flag game and there are some bugs that need to be fixed.

  1. The loop just stops after the round is over.
  2. If a player joins mid-game I think the UI will just show the current StarterGui.

Here are the main scripts:

--GameMain; script
local GameManager = require(game.ReplicatedStorage.Modules.GameManager)
local DisplayManager = require(game.ReplicatedStorage.Modules.GameManager.DisplaysManager)
local config = require(game.ReplicatedStorage.Modules.Configurations)

local Players = game:GetService('Players')

wait(1)

GameManager:Init()

while true do
	repeat
		GameManager.RunVotingIntermission()
	until GameManager.IntermissionRunning == false
	GameManager.GameStart()
	
	GameManager:StartWait()
	wait(1)
	GameManager:UpdateLoop()
	repeat
		wait()
	until GameManager.gameRunning == false
	
	GameManager.RoundOver()
	wait(5)
	GameManager.EndWait()
	GameManager.CleanUp()
	for i, player in pairs(Players:GetPlayers()) do
		DisplayManager:ShowFrame(player:WaitForChild("PlayerGui").Main, "Intermission")
	end
	wait(1)
	GameManager.IntermissionRunning = true
end
--GameManager; modulescript
local GameManager = {}

local Players = game:GetService("Players")

local Configurations = require(script.Parent.Configurations)
local mapsManager = require(script.MapsManager)
local TimeManager = require(script.TimeManager)
local DisplayManager = require(script.DisplaysManager)
local TimeFormatter = require(script.Parent.TimeFormatter)
local teamManager = require(script.TeamManager)

local camera = game.Workspace.CurrentCamera

--vars
GameManager.IntermissionRunning = false
GameManager.gameRunning = false

local savedMaps = game.ServerStorage.SavedMaps

function GameManager.Init()
	mapsManager:SaveMaps()
end

function GameManager.RunVotingIntermission()
	wait(1)
	GameManager.IntermissionRunning = true
	game.ReplicatedStorage.Remotes.StartIntermission:FireAllClients()
	for i, player in pairs(Players:GetPlayers()) do
		DisplayManager:ShowFrame(player:WaitForChild("PlayerGui").Main, "Intermission")
	end
		
	local secs = Configurations.INTERMISSION_TIME
	
	local Time = TimeFormatter:Convert(secs, "colon", true)
	TimeManager:UpdateTime("Intermission", Time)
	
	repeat
		if #Players:GetPlayers() >= Configurations.MIN_PLAYERS then
			if secs > 0 then
				secs = secs - 1
				local Time = TimeFormatter:Convert(secs, "colon", true)
				TimeManager:UpdateTime("Intermission", Time)
				wait(1)
			elseif secs <= 0 then
				print('lalalala')
				GameManager.IntermissionRunning = false
				print(tostring(GameManager.IntermissionRunning))
				break
			end
		elseif #Players:GetPlayers() < Configurations.MIN_PLAYERS then
			DisplayManager:SetText("Not enough players to start!", "Time", "Main", "Intermission", true)
		end
	until GameManager.IntermissionRunning == false
end

function GameManager.UpdateLoop()
	local secs = Configurations.ROUND_TIME
	
	local Time = TimeFormatter:Convert(secs, "colon", true)
	TimeManager:UpdateTime("ScoreboardTwoTeams", Time)
	
	repeat
		if secs > 0 then
			wait(1)
			secs = secs - 1
			local Time = TimeFormatter:Convert(secs, "colon", true)
			TimeManager:UpdateTime("ScoreboardTwoTeams", Time)
		elseif secs <= 0 then
			print('lalalala')
			GameManager.gameRunning = false
			print(tostring(GameManager.gameRunning))
			break
		end
	until GameManager.gameRunning == false
end

function GameManager:StartWait()
	local secs = Configurations.GAME_START_WAIT
	
	local Time = TimeFormatter:Convert(secs, "colon", true)
	TimeManager:UpdateTime("ScoreboardTwoTeams", Time)
	
	while true do
		if secs > 0 then
			wait(1)
			secs = secs - 1
			local Time = TimeFormatter:Convert(secs, "colon", true)
			TimeManager:UpdateTime("ScoreboardTwoTeams", Time)
		elseif secs <= 0 then
			break
		end
	end
end

function GameManager:EndWait()
	local secs = Configurations.GAME_END_WAIT
	
	local Time = TimeFormatter:Convert(secs, "colon", true)
	TimeManager:UpdateTime("ScoreboardTwoTeams", Time)
	
	while true do
		if secs > 0 then
			wait(1)
			secs = secs - 1
			local Time = TimeFormatter:Convert(secs, "colon", true)
			TimeManager:UpdateTime("ScoreboardTwoTeams", Time)
		elseif secs <= 0 then
			break
		end
	end
end

function GameManager:RoundOver()
	local winningTeam
	if GameManager.gameRunning == false then
		if teamManager:AreTeamsTied() then
			DisplayManager:SetText("Tie!", "Time", "Main", "ScoreboardTwoTeams")
		elseif not teamManager:AreTeamsTied() then
			winningTeam = teamManager:GetWinningTeam()
			DisplayManager:SetText(winningTeam.." won the game!", "Time", "Main", "ScoreboardTwoTeams")
		end
	end
end

function GameManager.CleanUp()
	for i, player in pairs(Players:GetPlayers()) do
		DisplayManager:HideFrame(player:WaitForChild("PlayerGui").Main, "ScoreboardTwoTeams")
		DisplayManager:HideFrame(player:WaitForChild("PlayerGui").Main, "Chat")
		DisplayManager:ShowFrame(player:WaitForChild("PlayerGui").Main, "Intermission")
		player.Neutral = true
	end
	mapsManager.ClearMap()
	DisplayManager:ClearTeamScores()
	DisplayManager:DestroyMinimap()
end

function GameManager.GameStart()
		GameManager.gameRunning = true
		game.Workspace.CurrentCamera.CameraType = Enum.CameraType.Custom
		local mapsAvailable = savedMaps:GetChildren()
		local randomMap = mapsAvailable[math.random(1, #mapsAvailable)]
		local creatorID = randomMap:WaitForChild("CreatorID")
		local creator = Players:GetPlayerByUserId(creatorID.Value)
		
		DisplayManager:SetText(tostring(creator), "CreatorName", "Main", "ScoreboardTwoTeams")
		DisplayManager:SetText(randomMap.Name, "MapName", "Main", "ScoreboardTwoTeams")
		mapsManager.LoadMap(randomMap.Name)
		DisplayManager:SetMinimapDisplayer(randomMap)
		
		print("success")
		
		game.Workspace.Lobby.SpawnLocation.Enabled = false
		print("Lobby spawn disabled")
		
		for i, plr in pairs(Players:GetPlayers()) do
			DisplayManager:ShowFrame(plr.PlayerGui:WaitForChild("Main"), "ScoreboardTwoTeams")
			DisplayManager:ShowFrame(plr.PlayerGui:WaitForChild("Main"), "Chat")
			DisplayManager:HideFrame(plr.PlayerGui:WaitForChild("Main"), "Intermission")
			teamManager:AssignPlayerToTeam(plr)
			print("Assigning player...")
			plr:LoadCharacter()
			print("Loading character...")
			wait()
		end
		game.ReplicatedStorage.Remotes.SetPlayerCameraType:FireAllClients()
		print('succesS.')
end

return GameManager
--IntermissionHandler; localscript
local player = game.Players.LocalPlayer
local cam = game.Workspace.CurrentCamera
local part = workspace.StartPart

local function Intermission()
	cam = game.Workspace.CurrentCamera 
	repeat
		cam.CameraType = Enum.CameraType.Scriptable
	until cam.CameraType == Enum.CameraType.Scriptable
	
	while cam.CameraType == Enum.CameraType.Scriptable do
		cam.CFrame = part.CFrame
		wait()
	end
end

local function MakeCameraTypeCustom()
	cam = game.Workspace.CurrentCamera
	cam.CameraType = Enum.CameraType.Custom
	cam.CameraSubject = player.Character:FindFirstChildWhichIsA("Humanoid")
end

game.ReplicatedStorage.Remotes.StartIntermission.OnClientEvent:Connect(Intermission)
game.ReplicatedStorage.Remotes.SetPlayerCameraType.OnClientEvent:Connect(MakeCameraTypeCustom)

So I’m back here again. I took a long break and now I want to fix these bugs!

I have no idea how to do the loop thing, and I think I may have an idea for #2.

Please help!

1 Like