How to get the assigned name of a value in a dictionary?

So this is a dictionary in which I want the dictionary assigned name not the actual object name,

local TeamToDepart = {
	["「CI」 Medical Department"] = game.Teams["C.I Medical Department"],
	["「CI」Special Experimental Operations Group | Sierra"] = game.Teams["C.I REDACTED"],
	["「CI」 Scientific Department"] = game.Teams["C.I Science Department"],
	["「CI」 Security Department"] = game.Teams["C.I Security Department"],
	["「CI」 Asset Welfare Department"] = game.Teams["C.I Asset Welfare"],
	["「CI」 Cryptic Military Corp"] = game.Teams["C.I Military Corp"],
	["「CI」 Dinosaur Actors"] = game.Teams["C.I Dinosaur Actors"],
	["「CI」 Engineering & Technical"] = game.Teams["C.I Engineering & Technical Department"],
	["「CI」 Administrative Department"] = game.Teams["C.I Administrative Department"]
}

So I made a for loop for this thought this would work,

local function AssignTeamFromDepartment(group, player)
	for i, v in pairs(TeamToDepart) do
		if v.Name == group.Name then
			player.Team = v
			break
		end
	end
end

Unfortunately the name is the objects actual name which I don’t want. I want to Dictionary assigned name.

Check i instead of v.Name, pairs for dictionaries return a key, value pair

1 Like

Yep, the numbers got changed to a string value I assigned, thanks! :heart:

1 Like