Need help with letting a Team win the round

I want to achieve that the last team which has players in it wins, and gets the reward.

I already made the team creating and dividing players into the team. I also tried to create a block of code that should end the round when all the other teams players are 0 and give the winning team the rewards. But this doesnt work, maybe someone can help me with this?

elseif map:FindFirstChild("Teams4") then
			roundType = "Teams4"
			
			local players = game.Players:GetPlayers()
			
			local redteam = Instance.new("Team")
			local blueteam = Instance.new("Team")
			local yellowteam = Instance.new("Team")
			local greenteam = Instance.new("Team")
			local dead = Instance.new("Team")
			
			redteam.Name = "Red"
			blueteam.Name = "Blue"
			yellowteam.Name = "Yellow"
			greenteam.Name = "Green"
			dead.Name = "Dead"
			
			redteam.TeamColor = BrickColor.new("Really red")
			blueteam.TeamColor = BrickColor.new("Deep blue")
			yellowteam.TeamColor = BrickColor.new("New Yeller")
			greenteam.TeamColor = BrickColor.new("Forest green")
			dead.TeamColor = BrickColor.new("Mid gray")
			
			redteam.Parent = game.Teams
			blueteam.Parent = game.Teams
			yellowteam.Parent = game.Teams
			greenteam.Parent = game.Teams
			dead.Parent = game.Teams
			
			
			local t = 1
			local Teams = {game.Teams.Red,game.Teams.Blue,game.Teams.Green,game.Teams.Yellow}
			for i,v in pairs(game.Players:GetPlayers()) do
				if  t == 1 then
					v.Team = Teams[1]
					t = 2
				elseif t == 2 then
					v.Team = Teams[2]
					t = 3
				elseif t == 3 then
					v.Team = Teams[3]
					t = 4
				elseif t == 4 then
					v.Team = Teams[4]
					t = 1
				end	
				for _, player in pairs(game:GetService("Players"):GetChildren()) do
				local char = player.Character
				connection = char:WaitForChild("Humanoid").Died:Connect(function() 
				print(player.Name .. " has died!")
				v.Team = dead		
			    connection:Disconnect()
			 end)
				end
			end
				
			local children = workspace.Ingame:GetChildren()
			for i = 1,#children do
				map:FindFirstChildWhichIsA("Tool"):Clone().Parent = children[i]
			end

			map:FindFirstChildWhichIsA("Tool"):Destroy()	
			
			if roundType == "Teams4" then
				repeat roundLenght = roundLenght -1
					status.Value = "Time left: "..roundLenght
					task.wait(1)
				until roundLenght == 0 or 
					redteam:GetPlayers() == 0 and blueteam:GetPlayers() == 0 and yellowteam:GetPlayers() == 0 or 
					blueteam:GetPlayers() == 0 and yellowteam:GetPlayers() == 0 and greenteam:GetPlayers() == 0 or 
					redteam:GetPlayers() == 0 and yellowteam:GetPlayers() == 0 and greenteam:GetPlayers() == 0 or 
					redteam:GetPlayers() == 0 and blueteam:GetPlayers() == 0 and greenteam:GetPlayers() == 0 
				
				if redteam:GetPlayers() == 0 and blueteam:GetPlayers() == 0 and yellowteam:GetPlayers() == 0 then
					status.Value = "Winner: "..greenteam.Name
				elseif blueteam:GetPlayers() == 0 and yellowteam:GetPlayers() == 0 and greenteam:GetPlayers() == 0 then
					status.Value = "Winner: "..redteam.Name
				elseif redteam:GetPlayers() == 0 and yellowteam:GetPlayers() == 0 and greenteam:GetPlayers() == 0 then
					status.Value = "Winner: "..blueteam.Name
				elseif redteam:GetPlayers() == 0 and blueteam:GetPlayers() == 0 and greenteam:GetPlayers() == 0 then
					status.Value = "Winner: "..yellowteam.Name
					
				
				end
				
				redteam:Destroy()
				blueteam:Destroy()
				yellowteam:Destroy()
				greenteam:Destroy()
				dead:Destroy()
					
				end
			end

Hello there :slight_smile:
Your script should work fine. There seems to be a very minor issue though. To get the number of elements inside a table, put # before it. In the code, you have just been saying redteam:GetPlayers() == 0. Instead you should write: #redteam:GetPlayers() == 0.
That should probably fix your script. Just put # as a prefix every time you are trying to compare a team’s players with a number.

Thanks! i didnt know that. It works fine now :slight_smile: