Round system not working?

Im rewriting my old round system so i can make a better one, i tried running it and when i played the game, it got stuck printing “Enough players!”


intermissionduration = 10
preparationduration = 15
roundduration = 30



--remote events

prepevent = script.Preparing
roundstartevent = script.RoundStart
roundendevent = script.RoundEnd
intermissionevent = script.Intermission
loadingevent = script.LoadingGUI

--map folder and others

mapfolderlist = game:GetService("ReplicatedStorage").Maps:GetChildren()


print("amount of maps: "..#mapfolderlist)

function StartRound()
	
	--pick a random map
	
	local randmappick = math.random(1, #mapfolderlist)
	local mapindex = mapfolderlist[randmappick]
	local maptobepicked = mapindex:Clone()
	maptobepicked.Parent = workspace.CurrentMap
	print("map picked: "..maptobepicked.Name)
	
	--teleport players to the map
	
	workspace.Map_Loaded:WaitForChild(maptobepicked.Name)
	
	
	
	local spawns = maptobepicked:WaitForChild("!_Spawns")
	
	
	for i, v in pairs(game.Players:GetChildren()) do
		
		if v.Character then
		
		local char = v.Character
		
		--get a random spawn for them
		
		local randspawn = math.random(1, #spawns)
		local spawnindex = spawns[randspawn]
		local pickedspawn = spawnindex
		
		char.HumanoidRootPart.CFrame = pickedspawn:FindFirstChild("PLRPOS").CFrame
		
		end
	end
	--wait for the round prep
	
	wait(preparationduration)
	
	roundstartevent:Fire()
	print("round started")
	
end

function EndRound()
	
	roundendevent:Fire()
	print("round ended")
	
	task.wait(10) --how much time the map hangs around for before getting destroyed
	
	local mapfolder = workspace.Map_Loaded:GetChildren()
	mapfolder:Destroy()
	
	if mapfolder == nil then
		
		warn("Did not find a map to destroy.")
		
	end
	
end

function Main()
	
	print("Waiting for Players...")
	
	while true do
	
	task.wait(2)
	
		local plrs = game:GetService("Players"):GetChildren()
	
	if #plrs >= 0 then
		
		print("Enough players!")
		
		task.wait(1)
		
		for i = intermissionduration, -1 do
			
			wait(1)
			print("Intermission: "..i)
			if i == 0 then
					StartRound()
					
					--placeholder
					
					for i = preparationduration, -1 do
						wait(1)
						print("Preparation: "..i)
						if i == 0 then
							roundstartevent:Fire()
						end
						
						for i = roundduration, -1 do
						 
						 wait(1)
						 print("Round:"..i)
						 
						 if i == 0 then
							EndRound()
						   end
						end
					end
					
					
					
			end
			
		end
	
	else
			
			print("Not enough players...")
			wait(5)
	end
	
	task.wait(5)
	
   end
end

Main()```

You need to use three tildas, not one.

for i = intermissionduration, -1 do

This for loop isn’t ever going to run if intermissionduration >= 0. Did you intend to do this instead?

for i = intermissionduration, 0, -1 do
2 Likes

Yes! but now theres another issue, when the map loads, everything fine until the preparation phase, it starts the preparation but immedeately starts the round, skipping the preparation phase.

image

(What the output says)

1 Like

You will have to change all the other for loops too.

1 Like

Okay i think i fixed it, now all i gotta do is fix the spawns which send me to the wrong place.