How would I get certain value from key in dictionary?

I made a dictionary and inside of dictionary, there are multiple keys that have 2 different value in each key of Name and CFrame

How would I only print out CFrame value of the key?

For example, if the table was

local playerPlacedStructuresDictionary = {
	A = "Lemon", "36, 61.0250015, -388, 1, 0, 0, 0, 1, 0, 0, 0, 1"
}

how would I print out only CFrame value which is 36, 61.0250015, -388, 1, 0, 0, 0, 1, 0, 0, 0, 1

2 Likes

Couldn’t you just do

print(DictionaryHere.A[2])

?

1 Like

thats a tuple and wont work. we need to pack it.

example:

table.pack(dictionary.A)[2]

1 Like

Try this instead of using that. (this is a example script. change how you need)

local dictionary = {

["Lemon"] = CFrame.new(1,2,3,4,5,6), -- separate each line with a ","

["apple"] = CFrame.new(21,42,69,420,999,14)

}
2 Likes

Then we can get the value by doing

dictionary["apple"]

to get the cframe of the apple

1 Like

ah actually I got my dictionary good, the lemon was just an example

thank you a lot though, it helped me

bruh you gave me the solution and took it away?

1 Like

nevermind, I should have made my post more clear, I couldn’t make my key inside of dictionary have only one value, because I need both name and position of an object inside of key, which happens to be automatically done by other lines of the script.

I tried table.pack(dictionary.A)[2] in dictionary but it somehow gives nil value… its not because other lines of code is giving nil because when I print directly the table, it gives both of value that is not nil

I don’t quite understand, @AC_Starmarine 's answer should have been good enough.

local dictionary = {
    ["Lemon"] = CFrame.new(1, 2, 3), -- separate each line with a ","
    ["Apple"] = CFrame.new(21, 42,69, 420,999)
}

You can then do:

for i, v in next, dictionary do
    print(i) -- Name
    print(v) -- CFrame
end

If you would like more control over the dictionary, like not having to use for i, v in next every time just to get the name, then you can order your dictionary like this instead:

local dictionary = {
    {"Lemon", CFrame.new(1, 2, 3)},
    {"Apple", CFrame.new(21, 42, 69)}
}

Then use dictionary[1][1] for “Lemon” name, dictionary[1][2] for lemon CFrame, dictionary[2][1] for “Apple” name, and dictionary[2][2] for apple CFrame.

1 Like

Well originaly he had a tupple instead of a table so you couldn’t just do stuff.

1 Like

I meant the key which is A had 2 values which is Name and CFrame, how would I only get one of value which is CFrame

There was a } at the end of his initial post, so I assumed he accidentally cut off his table when posting. If it was a tuple, then yes, you would use table.pack

1 Like

oh my god, I am so sorry yall, my first line got cut off for somereason…

You have a tuple, change it to this:

local playerPlacedStructuresDictionary = {
	A = {"Lemon", CFrame.new(36, 61.0250015, -388, 1, 0, 0, 0, 1, 0, 0, 0, 1)}
}

Then call it using playerPlacedStructuresDictionary[A][2]

1 Like

oh ok I will try thanks for the help

wow exactly what i said and he gets the solution.

1 Like

I mean I was looking for [A][2], you said table.pack(dictionary.A)[2]

Even though that wasn’t what I was looking for, thanks for helps though!