Help fixing round system

working on a round script and its not saying I’m the winner after 1 round it breaks idk how to fix it here is the script

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()
				round.ReturnPlayers(lobby)
			end
		end

		task.wait(1)
	end

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

until Message == "Idk"

here is what it does (CHECK THE OUTPUT)

help is appreciated

try putting it into a

while task.wait() do

--round code

end

instead of your

repeat 

--round code

untill Message == "Idk"

try doing that

still does not work I don’t know?

Found the issue. In this if then statement:

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

You’re not clearing the playersinRound table. So when the round restarts, the player is added to the table again, and now there’s 2 people on it. In which case, your code returns and does nothing else.

2 Likes

wait did I forget to add that in?? I am dumb that is crazy because bc I made a system like this about 9 months ago and forgot this exact statement… and now did it again tysm though

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