So i was trying to make a script that will check if a team is teamed with the current team the player is on but some reason it won’t work?
Script:
local function CheckTeammate(plr1, plr2)
for i,v in pairs(LoadingModule.GetTeam) do
if i == plr.Team.Name then
if plr2.Team.Name == v then
print(v)
return v
end
end
end
end
You’re comparing the team name of the plr2 to a table, you need to loop through all the teams inside the table and check if plr2 team correspond to any of the teams inside the table
local function CheckTeammate(plr1, plr2)
for i,v in pairs(LoadingModule.GetTeam) do
if i == plr.Team.Name then
for j,k in pairs(v) do
if plr2.Team.Name == k then
print(v)
return v
end
end
end
end
end
I expect the output to be the team name in the table but instead I get nothing.
You’re getting nothing because LoadingModule.GetTeam is an array and not a table. Thus, the for i,v in pairs(LoadingModule.GetTeam) do loop will never execute because pairs iterates over a table and not an array.
If you want to check if a given player is on the same team as another, use the Player.Team property: if plr.Team == plr2.Team then
print(plr2.Team)
end