Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

attempt to index nil with Pumpkin?

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

6 comments

0

There are so many things wrong with this post, for example you do not give us the error.

0

its in the title

0

hasanchik attempt to index nil with Pumpkin is the error

1

objectStats is nil

0

Firstly, what is "ss", what is "item" and what is objectStats

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

1 answer

✓ Accepted answer

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.

1 comment

0

my code is like 700 lines long so it might not remember the variable. but i did use require

This discussion is preserved as it was. New answers, comments, and votes are closed.