See if a player is on a team in a table

The title pretty much says it all, but I’m trying to see if a player is on a specific team from a table and if so then it will do code I add later.

Code so far:

local function FindTeam(StaffTeams) -- This function run a loop through the table(Teams) and return the short name. 
	for i, v in pairs(StaffTeams) do
		if i == StaffTeams then
			--I'll add Code here Eventually-
		end
	end
end

And the full script if you are interested:

local player = game.Players.LocalPlayer
local CharacterImage = script.Parent.CharacterImage
local RealName = script.Parent.RealName
local DisplayName = script.Parent.DisplayName
local Rank = script.Parent.Rank
local StaffTeams = {
	["C-Suite"] = true,
	["Core Team"] = true,
	["Secondary Team"] = true,
	["GFX Artist"] = true,
	["Studio Developer"] = true,
	["Studio Manager"] = true
}

local function FindTeam(StaffTeams) -- This function run a loop through the table(Teams) and return the short name. 
	for i, v in pairs(StaffTeams) do
		if i == StaffTeams then
			--I'll add Code here Eventually-
		end
	end
end
local function FindTeam(StaffTeams) -- This function run a loop through the table(Teams) and return the short name. 
	for i, v in pairs(StaffTeams) do
		if i == player.Team.Name then
			--I'll add Code here Eventually-
		end
	end
end

You’re storing the team names as keys within the dictionary so just compare them with the “Team” property of the “Player” instance (this is the “Team” instance itself but by using the “Name” property shared by all instances we can get the name as a string value).

Remember to call the function by the way, since I see you haven’t done in the provided script.

This doesn’t seem to be working either.

Alternatively:

local function FindTeam(StaffTeams) -- This function run a loop through the table(Teams) and return the short name. 
	for i, v in pairs(StaffTeams) do
		if i == tostring(player.Team) then
			--I'll add Code here Eventually-
		end
	end
end

Both should be working providing everything else in the script is correctly referenced.

a.rbxl (32.1 KB)

You can test here.

local players = game:GetService("Players")
local player = players.LocalPlayer
local CharacterImage = script.Parent.CharacterImage
local RealName = script.Parent.RealName
local DisplayName = script.Parent.DisplayName
local Rank = script.Parent.Rank

local StaffTeams = {
	["C-Suite"] = true,
	["Core Team"] = true,
	["Secondary Team"] = true,
	["GFX Artist"] = true,
	["Studio Developer"] = true,
	["Studio Manager"] = true
}

for i, v in pairs(StaffTeams) do
	if i == player.Team.Name then
		print(player.Team.Name)
	end
end

image

The team names are stored as keys in this particular dictionary. I also already proved above that it’s working.

Yeah, I only noticed after I posted which is why it’s marked for deletion