Uhmm, so you might recognise me from the dialogue thingy but ummmm.
I got an error saying; Players.maxpax2009.PlayerGui.ScreenGui.LocalScript:15: attempt to index nil with 'Name'
How do you really acess a table?
local PartsToDialogue = {} for i, v in pairs(game.Workspace.DIalogues.Models:GetChildren()) do table.insert(PartsToDialogue, v) end print(PartsToDialogue.v.Name) --Attempt to index nil with 'Name?'
There Are 2 Types of Tables
Lists
Dictionaries
Lists
local listTable = {"a","b","c"}
Now this is a regular table that holds these 3 values as Strings.
If we wanted a certain value from this table, we would have to Index it with [ ]
For Example, if we wanted to get b from this table we would do...
print(listTable[2])
The result of this would print b in the output because we are indexing or getting the second value that is in the table.
We can also do this with for loops, like so...
for i = 1, #listTable, 1 do print(listTable[i]) end
This will print all the values in the table because we are starting at 1, to the number of items in the table, which is 3, by the increment of 1. So, the result of this will print a b c
.
This is just doing the same thing three times, just simpler...
print(listTable[1]) print(listTable[2]) print(listTable[3])
This is a bad habit and inefficient, it would be better to do a for loop
.
Another cool thing you can do with indexes is doing these for children of an object!
local items = game:GetService("Workspace"):GetChildren()
for i = 1, #items, 1 do print(items[i].Name) end
This will print the name of all the children inside of Workspace, since we are using the same thing we did for the listTable
.
Dictionaries
Now dictionaries are like lists, just with subtables inside of the values.
local newDictionary = { ["Value1"] = { ["Green"] = {0,255,0}, ["Red"] = {255,0,0} }, ["Value2"] = { ["Blue"] = {0,0,255}, ["Black"] = {0,0,0} }, ["White"] = {255,255,255} }
This is just a table inside of a table holding multiple values of tables!
Dictionaries have unlimited possibilities, especially when you encounter metatables!
So, if you wanted to get the value of Red you would have to index the dictionary with [ ]
...
local redDirectory = newDictionary["Value1"]["Red"] -// This will return the table, so we'll have to index the table that the value holds print(redDirectory[1]) --// Results in printing 255, as that's the first value in the table.
Most of the things you do with listing tables, you can do with dictionary tables!
Possibilities are endless!
Hope this helped! Feel free to select this as an answer if this helped you!
You are trying to get the values in a table by using the value which is not going to work. Tables have an index assigned to every value in it. Doing table.insert gives a numeric index to the value. By doing PartsToDialogue[1].Name, you can get the name of the first value in the table.
I can't explain it to you if you don't want to 'sleep'.