Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

attempt to index nil with Pumpkin?

Asked by 3 years ago

so im trying to make a food system. people grab food and get it in their inventory this is a little bit of my code:

local itemName = item.Name
local itemStat = objectStats[itemName] -- error is here
local tangible = ss.Items:FindFirstChild(itemName)

in the module script:

local module = {
    ["Pumpkin"] = {
        ["image"] = 453112717,
        ["edible"] = true,
        ["hunger"] = 12,
        ["thirst"] = 5,
        ["heal"] = 3,
        ["bundleSize"] = 1,
            },
}
return module
0
There are so many things wrong with this post, for example you do not give us the error. hasanchik 49 — 3y
0
its in the title NoobPowerPlayzz 15 — 3y
0
hasanchik attempt to index nil with Pumpkin is *the* error bostaffmanbulgaria1 89 — 3y
1
objectStats is nil Leamir 3138 — 3y
View all comments (2 more)
0
Firstly, what is "ss", what is "item" and what is objectStats msdarckdu802 65 — 3y
0
also you're not using require() for that module script . unless its in the bit you didnt show. If its there ignore me lol TGazza 1336 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

Obviously objectStats doesn't exist. Odds are you made a typo.

Please check your variable names next time you write code so you don't make the same mistake and come begging for us to fix your code. It's unreal and downright unnecessary.

Did you possibly forget to define objectStats, or did you just define it as local inside of a higher scope where the script can't read it?

Or did you forget to assign the variable to the required module?

local objectStats = require(script.Module) -- The module location inside of require()

Sometimes you slip up. Sometimes you make mistakes that need to be corrected. Try correcting them before coming to us.

0
my code is like 700 lines long so it might not remember the variable. but i did use require NoobPowerPlayzz 15 — 3y
Ad

Answer this question