local function returnteammembers(team,targets)
	local members = 0
	for _,v in pairs(targets) do
		if game.Players[v].TeamColor == team.TeamColor then
			members = members +1
		end
	end
	return members 
end

function randomizeteams(target)
	local targets = target
	local team1 = {}
	local done = false
	local ceil = math.ceil(#targets/2)
	local players = game.Players:GetChildren()
		for i = 1,#targets do
			
			if not done then
				local tempmath = math.random(1,#players)
				if table.find(targets,players[tempmath].Name) then
					players[tempmath].TeamColor = BrickColor.new("Bright red")
					table.remove(targets, tempmath)
				end
				if returnteammembers(game.Teams.Red,targets) == ceil then
					done = true
			end
		for i = 1,#players do
			if table.find(targets, players[i].Name) then
				players[i].TeamColor = BrickColor.new("Bright blue") 
				end
			end
		end
	end
end

I cant figure out why this fails, no errors but everyone is team blue

3 comments

0

target is a list of players that are targetted

0

returnteammembers can be simplified to #team:GetPlayers() :P

0

Can I See The Teams Folder In The Explorer