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

How do I call values from this table?

Asked by 10 years ago

Hi. I asked this a few weeks ago but I'll post it again with some added information.

I have a table that stores questions and four possible answers, of which only one is correct. I found that I could create a table as follows and I found this code from a lua helpsite not specific to ROBLOX. I can apparently read values from this table by print(GeneralKnowledge[1][2]) to print "London" however this doesn't seem to work correctly.

GeneralKnowledge = {}
for i = 1, 4 do
    GeneralKnowledge[i] = { 0,0,0,0,0 }
end 
GeneralKnowledge[1] = {"What is 2+2?","2","3","4","i"}
GeneralKnowledge[2] = {"What is the capital city of the UK?", "London","Belfast","Dublin","Cardiff"}

Can anyone help? There is the following error. print(GeneralKnowledge[1][2]):1: attempt to index global 'GeneralKnowledge' (a nil value)

The table is stored within a script in the startergui.

Thanks.

1
Are you using that print line from within the script GeneralKnowledge is defined within? ROBLOX doesn't share environments between scripts. adark 5487 — 10y

1 answer

Log in to vote
-2
Answered by 10 years ago

Hmm...strange, it says your table is nil. In other words it's not there. I've had problems like this before. Just thought I'd point that out.

Ad

Answer this question