How do I identify the name of an object in a dictionary

local objects = {
["Hello"] = "World",
["2"] = "3"
}
for i, v in pairs(objects) do
     local stringvalue = instance.new("StringValue", location)
     stringvalue.Name = --I'd like to get "Hello"
     stringvalue.Value = --I'd like to get "World"
end

How would this be accomplished?

i,v is referring to index, value

the “name” of the object in your dictionary is the index. v is the value.

i = “Hello”
v = “World”

does that make sense?

I thought i was the number, I thought it counted UP for every loop. tysm it makes sense now.

It didn’t work. Here’s my code:
Data is the dictionary

	if Success then
		if Data == nil then return end
		print(Data)
		for Dictionary, Key in ipairs(Data) do
			local offense = Instance.new("StringValue", DisciplinaryFolder)
			offense.Name = Dictionary
			offense.Value = Key
		end

	else
		warn(errorMessage)
	end

No changes were made to the folder

When you’re just using an array {“Hello”, “World”} the index defaults to an integer counting up from one, dictionaries assign one manually.

ipairs stands for integer pairs, swap it to just pairs.

2 Likes