Hi,
Why i keep getting this error: "attempt to index nil with 'Parent"
This is where error happening:
local DATA = require(game.ReplicatedStorage.Assets.Data)
local A = DATA.script.Parent.Parent.Parent.Parent.Parent.Name.Table
its Name is “MyPart”
error is at line 2


Script is my script
theres also everything fine.
Any ideas why this happening?
What is the module “Data” returning?
i want to access Table that in screenshot 2
So what is “DATA.script.Parent…” supposed to be? The script seems to be acting like the module returns a part, but as you can see it appears the module returns a table. Please send a screenshot of the full code inside the module “Data”
local module = {
["MyPart"] = {
Type = {"Steel", 100},
Table = {
{"Wood", 5},
{"Iron", 60},
{"Stone", 25},
}
}
}
return module
Okay, so that makes sense as to why your script isn’t working. “DATA.script” is not a thing. Therefore, when you said “DATA.script.Parent,” you were indexing something that doesn’t exist (“a nil value”) with “parent.” I am not quite sure what you are trying to do in your script, though, so I couldn’t tell you what to do in order to fix it. If you want to access the “MyPart” table in the module, all you have to do is A = DATA.MyPart
2 Likes
i want to access table for my current part because i want to get which type is this part/model and what is lower tier for this (stone,iron,wood). But i don’t want to write script for for every thing. i want script that will automatically access table that named like model
To “access the table named like the model” (which is “MyPart”), all you need to do is:
local A = DATA.MyPart
but there will be more tables like not only MyPart, also Stone, Iron. I will rename MyPart to Steel. So i wanted to access table according to models name, but this give an error
Well yeah, but if you have “A = DATA.MyPart,” you can just grab all those subtables by doing stuff like A.Table[1][1] (that would grab wood, for example). It seems like you’re confused on how tables or modules work. I suggest do some research on them using the DevHub so that your script will make more sense to you.