Team Script Help

Hello everyone, so I made a script that puts certain people in a Team, everything works in Roblox Studio, but in roblox it doesnt, and its just 1 team that doesnt work.
If anybody could help me I’d be very greatful, thx.

Script:

local participantes = game.Teams.Participantes
local espectadores = game.Teams.Espectadores

local jugadores = {
	
	"00joel59", "ANGELOROJAS3", "helengatita", "williamcrak3012", "Pedro56789010", "FamedSeb", "ItxHector_x", "rafatech506", "matteorochop", "gaproo274_YT",
	"not0perripro0MBP", "whyamillive2", "mario_gogeta03", "SrCabezaCono", "claudikawaii111", "HOLAKEASE973", "ssofcmgamer0818", "Martin17rg",
	"Martin17rg", "Dsimphony0007", "Provisionjes", "hugato7", "erpiruverde", "laviniacraft450", "Danieliti2008", "BatiChuloMag321", "XxByproxX1", 
	"abcdefghijklmnopipi", "alexfoxypr", "Disam_Games", "elchorlitoXD", "EspiaALV2008", "BlueNeonSharks", "asbonil", "adamelkrak123", "albatrox_09",
	"Sonia_pro23", "Kennen93", "Meifandemaryykiroh", "Its_DaniiiXD", "IMelin19", "Catygamer12YT", "play54367", "ByPauMF13", "ElMenDelQuesoYT", "ormigit2", 
	"iAmAlex_Mx", "gjjd77", "juanarioman", "mijiyuter06", "MeyProxD", "RoLuisPr", "anghelinne", "LM_GAMERYKXB", "santiarobar", "Nutella7v7_49",
	"Thais_01x", "ItzLucas_xX", "Equipogamer_1", "pezpollito", "Lucastracas", "Ronalditoxdyolo", "angelvalentin2015", "XeroxX11", "mlynnwar", "CarlosyFernando_YT" ,
	"williamjugador2018", "mijagame86", "Sederiter_RXB", "RELOG2017", "Equipogamer_1", "alonsodn1601", "Lunatica_6783", "Pinguinito18", "el_catiux", "AlexGamerPro347", "Micabuela365"
}

game.Players.PlayerAdded:Connect(function(player)
	if table.find(jugadores, player.Name) then
		player.Team = participantes
	else
		player.Team = espectadores
	end
end)


1 Like

You should loop through the table with a for loop on the player added.

Like

game.Players.PlayerAdded:Connect(function(player)
for i, v in pairs (jugadores) do
	if table.find(v, player.Name) then
		player.Team = participantes
	else
		player.Team = espectadores
      end
	end
end)

Does that work?

Having one giant array is an inefficient way of doing this imo.

Would I be correct in assuming that everyone in that array has a certain rank or above in a specific group? If so, use Player:GetRankInGroup(GroupId) - this returns the players rank number from the groupid. If they are not in the group, this will return 0.

I cant do that, because many people arent in the group

still doesnt work, i dont know why

I came across the solution, i had to delete the “player.Team = espectadores” line