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

Square brackets are giving me a nil value?

Asked by 4 years ago

I am trying to get my script to find a random value within another folder but on like 16 where I use square brackets, it says that I attempted to index nil ([box]) with 'Q'.

01local numbersentered = {}
02 
03script.Parent.BackgroundFrame.QuestionNumber.Changed:Connect(function()
04 
05    local box = math.random(1,20)
06    print(box)
07    table.insert(numbersentered, box)
08 
09    for i,v in pairs(numbersentered)do
10        if box == v then
11            local box = math.random(1,20)
12            print(box)
13            table.insert(numbersentered, box)
14 
15        else
View all 24 lines...

Any help is wonderful!

0
Could you give the actual error? Roger111 347 — 4y
0
try Q:GetChildren()[box] greatneil80 2647 — 4y
0
Questions is a folder, 'Q' is the name of the string values inside the folder. It goes from Q1 to Q20. GoingToAnnoyYou 2 — 4y

2 answers

Log in to vote
0
Answered by
Roger111 347 Moderation Voter
4 years ago

ANSWER: So according to your error, it doesn't seem to have to do with box. Your error (translated) means that :FindFirstChild("Questions") is nil.

Note: I can't help you further until I see your hierarchy and what this Questions object is that you are looking for.

0
Questions is a folder which has a load of string values in it called "Q1" for example. It goes from Q1 to Q20. I am trying to get their values by calculating a random value, concatenating them and then bringing back the value of the string value into the script. GoingToAnnoyYou 2 — 4y
0
"Questions" is a folder inside the server storage. GoingToAnnoyYou 2 — 4y
0
Separate your references out. Instead of make a long line, reference each thing in a variable, and then when you get to `Q` you will see what the real problem is. Roger111 347 — 4y
0
Thanks, I'll do this. GoingToAnnoyYou 2 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

The full error is:

105:04:51.791 - Players.GoingToAnnoyYou.PlayerGui.ApplicationUI.QuestionScript:16: attempt to index nil with 'Q'
205:04:51.791 - Stack Begin
305:04:51.791 - Script 'Players.GoingToAnnoyYou.PlayerGui.ApplicationUI.QuestionScript', Line 16
405:04:51.792 - Stack End
0
Thanks for accepting my answer! Glad I could help! Also next time, you can just edit your question and add the stuff that someone asks for. And notify them via comment on their post. cheers! Roger111 347 — 4y

Answer this question