Team script problem

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 the script to pick players from lobby team, and not all players

  1. What is the issue? Include screenshots / videos if possible!

well, it takes all players in the game

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

well, i tried some stuff, but it didn’t work. i also searched solution on the internet (i am bad at scripting) also looked on Developer Hub

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

this script picks players and puts them in teams red/blue. also there is a lobby team. i need it to take players from lobby team

-- amount of players in each team
local BlueTeamCount
local RedTeamCount
-- amoungt of remaining players at the end of the round (and after round has started)
local remainingBlue
local remainingRed

inRound.Changed:Connect(function()
	
	if inRound.Value == true then
		
		BlueTeamCount = {}
		RedTeamCount = {}
		
		for i, plr in pairs(plrs:GetChildren()) do -- i tried changing this
			
			local char = plr.Character
			local humanRoot = char:WaitForChild("HumanoidRootPart")

			local allPlrs = plrs:GetChildren()
			
			-- will put the current player into a team with the less amount of players
			
			if #RedTeamCount > #BlueTeamCount then
				
				plr.Team = blueTeam
				humanRoot.CFrame = game.Workspace.BlueSpawn.CFrame
				
				table.insert(BlueTeamCount, plr.Name)
				print(plr.Name .. " put in ".. plr.Team.Name)
			elseif #BlueTeamCount > #RedTeamCount then
				
				plr.Team = redTeam
				humanRoot.CFrame = game.Workspace.RedSpawn.CFrame
				
				table.insert(RedTeamCount, plr.Name)
				print(plr.Name .. " put in ".. plr.Team.Name)
				
				math.random
				

i hope its a right topic, anything would be helpful

i am not so smart enough to figure it out, also just noticed my grammar-

is there any errors in the output, i dont know what line where to go to

Team instances have a :GetPlayers() function. Call that function on the lobby team and you will get a table containing all the players on that team

3 Likes

Do you just want one player to be assigned to a team? If so, instead of for loop-ing the Player’s children, just use local Random_Player = math.random(1, #Players:GetPlayers()), and then get one player by doing Players:GetPlayers()[Random_Player].

1 Like