Hello !
I’m trying to make like, if the remaining player are in the same team (or its allies), like it stops the round. I don’t ask for the full script, I can do it myself. I just want to know if there is anything that can handle something like this
If by teams you mean teams from Teams Service then if you have 2 players defined then you can do:
if player.Team == player2.Team then
print("The same team")
else
print("Different team")
end
It’s not exactly what I’m searching, they’ll problably be more than 20 players during a round. I can’t do this for every players. I’m searching something like automatic, such as a function, or things like this. Your method wold work for few players round, but not for bigger players round
The GetPlayers
method can be utilized on a Team Instance in the Teams
Service in order to retrieve an array of players that are currently on that team. This array will allow for more efficient comparisons between players that are still in the round.
Since I’m unsure of the specific use case, another way this could be achieved would be to use the length operator [#
] on the array which will enable the script to check if the amount of players in that team is equal to 0; if there’s only one team left with players, that would indicate that the remaining players are on the same team.
Loop, through the players, verifiying their TeamColor property.
Something like this.
local teamColor = game.Players:GetPlayers[1].TeamColor
local sameTeam = true
for i, v in pairs(game.Players:GetPlayers()) do
if v.TeamColor ~= teamColor then
sameTeam = false
break
end
end
if sameTeam then
---Stop round
end
You could wrap it all in a while loop (or connect it to RunService) if you want to check indefinitely. Hope it helps!