Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How would I find the name of a dictionary value?

for i, tools in pairs(MegaTable.Inventory) do
			game.ReplicatedStorage[tools.Name]:Clone().Parent = Player.BPK
			for i, toolstuff in pairs(tools) do
				if toolstuff.Name == "Color" then
					tools.Rarity.Color.Value = toolstuff
				elseif toolstuff.Name == "MaxUpgrades" then
					tools.Upgrades.MaxValue = toolstuff
				else
					tools[toolstuff.Name].Value = toolstuff
				end
			end
		end

The problem is, the .Name property doesn't work with values, (ex. you cant have local wasd = wasdddd and then do wasd.Name to get wasd). So how would I get the variable name, and not the variable value in a script? If you know any way, or think something might work, please post an answer. Thanks.

9 comments

0

The dictionary reference (index) is stored in the parameter "i" within your enumeration loop.

0

but what about the name, as a string value and not the iteration?

0

Your question is confusing?

0

like, to not get the number of how many its gone through, but instead to get the name of it. Lets say I had a sword in my inventory, when I loop through, how would I get the name of the sword in the loop, if its just loading from a table?

0

In an enumeration loop, "i" doesn't refer to the iteration, it refers to the index. In a Dictionary, 'i" is the reference.

0

so how would I get the name from i, and not a number?

0

..........

0

like if its {toolexample = 65}, in the loop, how do I get the name "toolexample", and not 1 from the index?

0

if you're looping with pairs, i is "toolexample" and v is 65

1 answer

In the case of a dictionary, the variable "i" in the for loop is not a number, is the string, that has a value inside.

This discussion is preserved as it was. New answers, comments, and votes are closed.