My round system wont work properly

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    i want to make a round system but it doesnt work properly.

  2. What is the issue? Include screenshots / videos if possible!
    after the round finishes, it shows the winner but then it wont make it intermission again when it should

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i tried rewriting the code following thedevking’s tutorial but didnt work.

here is my script:

local g,gtime,ing,st,chosen,plrs = game.ServerStorage.game,game.ServerStorage.time,game.ServerStorage.ingame,game.ReplicatedStorage.status,{},{}

game.Players.PlayerAdded:Connect(function(p)
	local random
	if #plrs<1 then
		random=1
	else
		random=math.random(1,#plrs)
	end
	table.insert(plrs,random,p.UserId)
end)

game.Players.PlayerRemoving:Connect(function(p)
	table.remove(plrs,table.find(plrs,p.UserId))
end)

g.Changed:Connect(function()
	if g.Value==false then
		for i=1,#plrs do
			local ch = game.Players:GetPlayerByUserId(plrs[i]).Character
			ch:SetPrimaryPartCFrame(workspace.spawn.SpawnLocation.CFrame)
		end
	else
		local randommap = math.random(1,#game.ServerStorage.maps:GetChildren())
		local map = game.ServerStorage.maps["map"..randommap]:Clone()
		map.Parent = workspace
		map.Name = "map"
		for i=1,2 do
			local random = math.random(1,#plrs)
			table.insert(chosen,plrs[random])
			game.Players:GetPlayerByUserId(plrs[i]).Character:MoveTo(workspace.map["spawn"..plrs[i]].Position)
			Instance.new("BoolValue",game.ServerStorage.ingame).Name=plrs[i]
		end
		
	end
end)

while wait() do
	if #plrs>=2 then
		for i=5,0,-1 do
			gtime.Value=i
			wait(1)
			gtime.Value=i
			st:FireAllClients(1,i)
			if i==0 then
				g.Value=true
			end
		end
		for i=30,0,-1 do
			gtime.Value=i
			wait(1)
			gtime.Value=i
			st:FireAllClients(2,i)
			if #game.ServerStorage.ingame:GetChildren()==1 then
				local win
				for _,v in pairs(game.ServerStorage.ingame:GetChildren()) do
					win=v
				end
				st:FireAllClients(5,game.Players:GetPlayerByUserId(tostring(win)).Name)
				game.ServerStorage.winner.Value=tostring(win)
				wait(3)
				workspace.map:Destroy()
				g.Value=false
			elseif #game.ServerStorage.ingame:GetChildren()<1 then
				st:FireAllClients(6)
				wait(3)
				workspace.map:Destroy()
				g.Value=false
			end
			if i==0 then
				st:FireAllClients(7)
				wait(3)
				workspace.map:Destroy()
				g.Value=false
			end
		end
	else
		st:FireAllClients(3)
	end
end

ik this is much but can somebody pls help me out?
also this is my first post so sorry if anything.

1 Like

What part isn’t working? Any errors? It would help if you were more specific.

oh i forgot to mention, there are no errors

Try adding print statements inside your while statment, see where it gets to.

ok
the output:
21:25:44.687 7b (x130) - Server - roundmgr:90
21:25:49.302 1b (x6) - Server - roundmgr:47
21:25:55.352 2b - Server - roundmgr:53
21:25:55.352 3a - Server - roundmgr:28
21:25:55.352 4a (x2) - Server - roundmgr:34
21:25:55.355 3b (x8) - Server - roundmgr:58
– from now on is after the round ended i think
21:26:03.435 4b - Server - roundmgr:64
21:26:06.449 1a - Server - roundmgr:21
21:26:06.449 2a (x2) - Server - roundmgr:23
21:26:06.449 3b - Server - roundmgr:58
21:26:07.451 4b - Server - roundmgr:64

the new script is:

g.Changed:Connect(function()
	if g.Value==false then
		print("1a")
		for i=1,#plrs do
			print("2a")
			local ch = game.Players:GetPlayerByUserId(plrs[i]).Character
			ch:SetPrimaryPartCFrame(workspace.spawn.SpawnLocation.CFrame)
		end
	else
		print("3a")
		local randommap = math.random(1,#game.ServerStorage.maps:GetChildren())
		local map = game.ServerStorage.maps["map"..randommap]:Clone()
		map.Parent = workspace
		map.Name = "map"
		for i=1,2 do
			print("4a")
			local random = math.random(1,#plrs)
			table.insert(chosen,plrs[random])
			game.Players:GetPlayerByUserId(plrs[i]).Character:MoveTo(workspace.map["spawn"..plrs[i]].Position)
			Instance.new("BoolValue",game.ServerStorage.ingame).Name=plrs[i]
		end
		
	end
end)

while wait() do
	if #plrs>=2 then
		for i=5,0,-1 do
			print("1b")
			gtime.Value=i
			wait(1)
			gtime.Value=i
			st:FireAllClients(1,i)
			if i==0 then
				print("2b")
				g.Value=true
			end
		end
		for i=30,0,-1 do
			print("3b")
			gtime.Value=i
			wait(1)
			gtime.Value=i
			st:FireAllClients(2,i)
			if #game.ServerStorage.ingame:GetChildren()==1 then
				print("4b")
				local win
				for _,v in pairs(game.ServerStorage.ingame:GetChildren()) do
					win=v
				end
				st:FireAllClients(5,game.Players:GetPlayerByUserId(tostring(win)).Name)
				game.ServerStorage.winner.Value=tostring(win)
				wait(3)
				workspace.map:Destroy()
				g.Value=false
			elseif #game.ServerStorage.ingame:GetChildren()<1 then
				print("5b")
				st:FireAllClients(6)
				wait(3)
				workspace.map:Destroy()
				g.Value=false
			end
			if i==0 then
				print("6b")
				st:FireAllClients(7)
				wait(3)
				workspace.map:Destroy()
				g.Value=false
			end
		end
	else
		print("7b")
		st:FireAllClients(3)
	end
end

so is there no solution to my problem?

Not sure, I have to go right now, I’ll take another look later.

ok, thanks for the update!
(30 ch)

Unfortunately I couldn’t find what’s wrong, perhaps you can try to get help from someone else? I’ll take another look later if possible.

It’s really weird since everything seems to be printing.

Is it because plrs table gets set to one player at the end and you are checking if the players is equal to or mroe then 2? Maybe it’s because "g" isn’t getting changed.

it should be. whenever a player is eliminated from the match, “g” (which stands for game) is changed.