Round system not working and i dont know why

local RoundSystem = {}
RoundSystem.__index = RoundSystem

function RoundSystem.New(Map)
	local self = setmetatable({}, RoundSystem)
	self.Name = Map.Name
	self.Map = Map
	self.Timer = 10
	self.IsGameCurrentlyOn = false
	self.IsGameCountingDown = false
	self.Bombs = {}
	self.Occupants = {}
	self.Team1 = {}
	self.Team1Score = 0
	self.Team2 = {}
	self.Team2Score = 0
	
	return self
end

function RoundSystem:SplitIntoTeams()
	for i, v in pairs(self.Occupants) do
		table.insert(self["Team".. tostring((i % 2) + 1)], v)
	end
end

function RoundSystem:UpdateInfoPart()
	local InfoPart = self.Map.InfoPart
	local StatsBillboard = InfoPart.StatsBillboard
	StatsBillboard.PlayersText.Text = "Players: ".. tostring(#self.Occupants)
	StatsBillboard.TimeText.Text = "Time: ".. tostring(self.Timer)
end

function RoundSystem:SendToSpawns()
	for i, v in pairs(self.Team1) do
		local Character = v.Character or v.CharacterAdded:Wait()
		Character:PivotTo(self.Map.Spawn1.CFrame)
	end
	
	for i, v in pairs(self.Team2) do
		local Character = v.Character or v.CharacterAdded:Wait()
		Character:PivotTo(self.Map.Spawn2.CFrame)
	end
end

function RoundSystem:AddBomb()
	local NewBomb = game.ReplicatedStorage.Models.Timebomb:Clone()
	NewBomb:PivotTo(self.Map.BombSpawn.CFrame)
	NewBomb.Parent = self.Map
	table.insert(self.Bombs, NewBomb)
	
	NewBomb.Destroying:Once(function()
		table.remove(self.Bombs, table.find(self.Bombs, NewBomb))
	end)
end

function RoundSystem:StartCountdown()
	self.IsGameCountingDown = true
	
	while self.Timer > 0 do
		self:UpdateInfoPart()
		self.Timer -= 1
		task.wait(1)
	end
	
	self.IsGameCountingDown = false
	
	if #self.Occupants >= 2 and #self.Occupants % 2 == 0 then
		self:StartGame(1)
	else
		self.Timer = 10
		self:UpdateInfoPart()
		self:StartCountdown()
	end
end

function RoundSystem:StartGame(Round)
	for i, v in pairs(self.Occupants) do
		v:LoadCharacter()
	end
	
	if Round == 1 then
		self:SplitIntoTeams()
	end
	
	self:SendToSpawns()
	self.IsGameCurrentlyOn = true
	self.AliveTeam1 = self.Team1
	self.AliveTeam2 = self.Team2
	
	for i, v in pairs(self.Occupants) do
		local Humanoid = v.Character:FindFirstChild("Humanoid")
		
		Humanoid.Died:Once(function()
			if table.find(self.AliveTeam1, v) then
				table.remove(self.AliveTeam1, table.find(self.AliveTeam1, v))
			else
				table.remove(self.AliveTeam2, table.find(self.AliveTeam2, v))
			end 
			
			if #self.AliveTeam1 ~= 0 and #self.AliveTeam2 ~= 0 then return end
			
			if Round < 5 then
				self:StartGame(Round + 1)
			else
				self:EndGame()
			end
		end)
	end
	
	self:AddBomb()
end

function RoundSystem:EndGame()
	for i, v in pairs(self.Bombs) do
		v:Destroy()
	end
	
	self.Occupants = {}
	self.Team1 = {}
	self.AliveTeam1 = {}
	self.Team2 = {}
	self.AliveTeam2 = {}
	self.Bombs = {}
	self.IsGameCurrentlyOn = false
	self.Timer = 30
	self:UpdateInfoPart()
end

return RoundSystem

i genuinely DO NOT GET WHAT IS WORKING AND I AM LOSING MY MIND. it should REGENERATE THE CHARACTERS AND TELEPORT THEM BUT IT DOESNT. WHAT AM I DOING WRONG???

it wont even let me check if the player is dead, im so done.

Theres no need to write a round system in a module script if it’s only gonna be required by 1 script. I’d recommend rewrting it in a normal script since module scripts work differently and are unpredictable.

1 Like