✓ Accepted answer
So first thing, when you use an in pairs loop, the variable that we commonly name i is the index of the member of the table that is getting looped.
local matable = {"gdfghh", false, 315}
for i, v in pairs(matable) do
print(i)
end
it's the second member.
Now, the v variable is the value that is getting passed through. so if we loop again.
local matable = {"gdfghh", false, 315}
for i, v in pairs(matable) do
print(v)
end
Now, that's a basic understanding of in pairs loop.
You are kind of using it wrongly by doing allowedTeams[v], you gotta do allowedTeams[i] cuz as we said that's the index. And you know you don't even need this. You can simply use v which will be the team that's looping each time.
Also, you're second mistake is, the values found in the allowedTeams table are strings. You pretty much did something similar to this.
"Cops".TeamColor
That will obviously error.
You gotta refer to the team object. So this is what you gotta do:
local allowedTeams = {
"Cops";
"SWAT";
"FBI";
"Staff";
}
(script)
for i,v in pairs(allowedTeams) do
if player.TeamColor == game:GetService("Teams"):FindFirstChild(v).TeamColor then
end
end
And that's it!
1 comment
Ah, I see. Thank you.