Help fixing round system bug

1 main problem

  1. it stops working due to the break on the main script

working on a round script here is my main script(script In scs)

local round = require(script.Round)
local info = game.ReplicatedStorage:WaitForChild("Info")
local Message = info:WaitForChild("Message").Value
local Inround = info:WaitForChild("InRound").Value
local maps = game.Workspace:WaitForChild("Maps"):GetChildren()
local lobby = workspace.Lobby

local playersinRound = {}

repeat
	
	local map = maps[math.random(1, #maps)]
	print(map)
	for intermission = 5,0,-1 do
		print("Game Starting In ", intermission)
		if intermission == 0 then
			round.SpawnPlayers(map)
		end
		
		for i, player in ipairs(game.Teams.Playing:GetPlayers()) do
			
			table.insert(playersinRound, player.Name)

			if #playersinRound >= 2 then
				return
			elseif #playersinRound == 1 then
				local playerwhowon = playersinRound[1]
				print(playerwhowon, "Is The Winner!!")
				wait(1)
				round.ReturnPlayers(lobby)
				break
			end

		end
		
		task.wait(1)
	end

	for Round = 5,0,-1 do
		print("Game Ending In ", Round)
		if Round == 0 then
			round.ReturnPlayers(lobby)
			Message = "Nobody Won D:"
			task.wait(1.5)
			Message = "Game Ended!"
		end
		task.wait(1)
	end
until Message == "Idk"

here is my module script in the main script

local inround = game.ReplicatedStorage:WaitForChild("Info"):WaitForChild("InRound").Value
local message = game.ReplicatedStorage:WaitForChild("Info"):WaitForChild("Message").Value
local maps = game.Workspace:WaitForChild("Maps"):GetChildren()

local playersinRound = {}

local round = {}

function round.SpawnPlayers(map)

	if inround then
		return nil
	else
		inround = true
		for i, player in ipairs(game.Players:GetPlayers()) do
			local char = player.Character
			local humrp = char:WaitForChild("HumanoidRootPart")

			humrp.CFrame = map.CFrame
			player.Team = game.Teams.Playing
		end
	end
end

function round.ReturnPlayers(lobby)
	if inround then
		inround = false
		for i, player in ipairs(game.Players:GetPlayers()) do
			local char = player.Character
			local humrp = char:WaitForChild("HumanoidRootPart")

			humrp.CFrame = lobby.CFrame
			player.Team = game.Teams.Watching
		end
	end
end

function round.FindWinner()
	for i, player in ipairs(game.Teams.Playing:GetPlayers()) do
		table.insert(playersinRound, player.Name)
		
		if #playersinRound > 1 then
			return
		elseif #playersinRound == 1 then
			local playerwhowon = playersinRound[1]
		end
	end
end

return round

here is what it does game

1 Like

the problem is that your playersinRound never gets resetted after each loop so it will increase each round, just set it to an empty table in the game ending loop

for Round = 5,0,-1 do
		print("Game Ending In ", Round)
		if Round == 0 then
			round.ReturnPlayers(lobby)
			Message = "Nobody Won D:"
			task.wait(1.5)
			Message = "Game Ended!"
			playersinRound = {}
		end
		task.wait(1)
	end
1 Like

thank you this has fixed the problem but another thing I forgot to mention is when there is a winner
the script doesn’t reset it keeps counting down until game time is over how do I fix this?

nvm I have fixed it ty for your help

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.