Is there a more efficient way to get the opposite of a 2 long array other than this?
local team=player.Team
local teams=game.Teams:GetChildren()
table.remove(teams,table.find(teams,team))
local OppositeTeam=teams[1]
print(OppositeTeam)
Is there a more efficient way to get the opposite of a 2 long array other than this?
local team=player.Team
local teams=game.Teams:GetChildren()
table.remove(teams,table.find(teams,team))
local OppositeTeam=teams[1]
print(OppositeTeam)
why not teams[2] ? I’m guessing you’ve already done that but no explanation as to why it didn’t work out?
If there is only two teams then as @J9White said, you can use teams[1] and teams[2]. I believe this should run a bit faster compared to using table.remove and table.find.
I recommend you make it into a function rather than typing that out every time. Other than that, there shouldn’t be a huge performance difference these two and even other methods out there.
function GetOpposingTeam(player)
local team = player.Team
local teams = game:GetService("Teams"):GetChildren()
return teams[1] == team and teams[2] or teams[1]
end
local Teams = game:GetService("Teams"):GetTeams()
local function GetOpposingTeam(player: Instance)
local team1: Instance = Teams[1]
return team1 == player.Team and Teams[2] or team1
end
Actually I’ve just encountered the same exact problem as he has so now I understand why he can’t just do team[2] but you could invert 1 or 2 and store the team you’ve currently got a direct reference to?
I assume the issue that you encountered was that :GetChildren() does not give an ordered list (apparently it gives the list ordered by the child added first? But that is not useful for me (could be used in a :GetOldest() function maybe))
I struggle to understand what you mean by inverting 1 and 2; and storing storing the team I have on reference, as I already do that with local team=player.Team.
I was trying to add +1 for the team who had possession so I could get possession stats as a percentage and -1 for the team without possession. @BulletproofVast’s solution worked for me