Indexing Nil on a non-nil value

Hello, I am trying to have the following code get the “TierNumber” from my module script, as below


The issue with this above is if I change

local TierNumber = ItemDataModule[CurrentWorkbench].Resources.Tier

to

local TierNumber = ItemDataModule[CurrentWorkbench][Category].Tier

It says this is index nil with Tier, even though the script is printing Category as “Resources”

Any ideas would be appreciated.

I can also provide more information if needed

1 Like

can u print

print(Category)
print(type(Category))
print(CurrentWorkbench)
print(unpack(ItemDataModule[CurrentWorkbench]))
xpcall(function()
   print(unpack(ItemDataModule[CurrentWorkbench][Category]))
end, function() warn("wrong") end)

and send me the console

1 Like

The itemdata for the category and workbench itself both resulted in nothing in the console
image

Below is the workbench data
image

1 Like

it’s because

ItemDataModule[CurrentWorkbench]

is empty as shown by the result of the unpack

1 Like

Well even when doing this

print(unpack(ItemDataModule["Workbench Tier 1"]))

It still doesn’t get any data even though the image in my previous reply shows there is indeed data in that table

1 Like

print this then

ItemDataModule
1 Like

After doing this, ive tried doing this at the beginning of the script where its being defined

local ItemDataModule = require(game.ReplicatedStorage.GameSettings.ItemData)
print(unpack(ItemDataModule))

Even here it doesn’t even recognize the module
image

Not sure if this is a me issue or a studio issue at this point

1 Like

does itemdatamodule exist in that variable?
try writing it like this:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GameSettings = ReplicatedStorage:WaitForChild("GameSettings")
local ItemDataModule = GameSettings:WaitForChild("ItemData")

local ItemData = require(ItemDataModule)
print(unpack(ItemDataModule))
2 Likes

thank ya, I don’t know how that never crossed my mind but thanks a lot.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.