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

What does this error attempt to index global 'items' (a function value) mean and how do I fix it?

11:42:05.548 - Players.VECTORGRAPHIC.PlayerGui.ScreenGui.newshop:109: attempt to index global 'items' (a function value)

This is what items is

items={

{"Sword",50,"http://www.roblox.com/asset/?id=32801243",

"Buying this will increase the rate at which you dig by 150 percent. This can be very useful when mining for points."},

{"DarkHeart",1000,"http://www.roblox.com/asset/?id=32801656",

"Buying this will increase the damage that you deal with the swuvle by 150 percent. This can be very useful when sword fighting."},

{"Sniper+",100,"http://www.roblox.com/asset/?id=32801218",

"The top grade sniper reloads 150 percent faster aswell as dealing 150 percent more damage than the normal sniper. This new sniper will replace your old one."},

{"Medkit",100,"http://www.roblox.com/asset/?id=32801669",

"After buying, you will find that you spawn with one medkip. A medkip can be used once, in battle, to fully heal you. Medkips can be very useful when getting away with the enemy flag. i herd u liek medkipz?"},
}

--here is what errors
```lua
sp.Store.InfoBox.Title.Text=items[selected][1]

1 comment

0

Can you provide what "selected" is? I feel like a lot of code here is missing.

1 answer

Somewhere in your code, the variable "items" is being defined as a function.

Skim through your code and make sure that the variable is unique, and nothing else is overwriting the variable.

Here's a tip: If lua ever says you're trying to index something invalid, you're probably trying to path a variable / object that is nil, or doesn't have a path.

For example, you can't do this:

function a()
end

print(a.waffle)

because "a" is a function, and it has no path. Doing this will throw the error that you're getting right now.

However, you can do this:

local Table = {
	A = {
		B = {
			C = 'waffle'
		}
	}
}

print(Table.A.B.C)

because the Table can be indexed and pathed like how you would when you're browsing through workspace, or anywhere else.

You also cannot do this:

local NilValue = nil;
print(NilValue.Descendant)

as it will throw an "attempt to index local NilValue ( a nil value)" error. Good luck!

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