Using For Loops

Hi, I’m trying to make a multiple choice test using a for loop. The questions can only appear once, and in a random order. Here’s what I go so far. Do I make 5 more for loops one for each question? I wrote the questions as “Red” “Orange” “Yellow” “Green” etc. because it will show a random picture and the player has to pick which color. What do I do next? Do I add scripts to the text buttons. This is my first time doing something like this so I have no clue.

local questions = (
  {"Red",{"Red","Orange","Yellow","Green","Blue","Purple"},1}
  {"Orange",{"Red","Orange","Yellow","Green","Blue","Purple"}2}
  {"Yellow",{"Red","Orange","Yellow","Green","Blue","Purple"}3}
  {"Green",{"Red","Orange","Yellow","Green","Blue","Purple"}4}
  {"Blue",{"Red","Orange","Yellow","Green","Blue","Purple"}5}
  {"Purple",{"Red","Orange","Yellow","Green","Blue","Purple"}6}
}

local numberCorrect = 0
local NumberOfQuestions = 6

for _ = 1,NumberOfQuestions do
	local TempQuestionNumber = math.random(1,NumberOfQuestions)
	local QuestionData = questions[TempQuestionNumber]
	local {"Red"}, {"Red","Orange","Yellow","Green","Blue","Purple"}, 1 = unpack(QuestionData)
	table.remove(question,TempQuestionNumber)
end

--Add the other five for loops here?

local percentCorrect = math.floor(numberCorrect/NumberOfQuestion * 100)

Thanks for reading
Sir.Play_MazeOfHeck

No, you can instead nest this in another loop.

for _, question in ipairs(questions) do
    local color = question[1]
    -- do something
end

You can use a dictionary to filter out any generated results that have already been used. You were on the right path when you used NumberOfQuestions however because it’s defined within the loop, it will only exist within that particular iteration of the loop and when it goes on to the next iteration, it won’t exist anymore (it will just be recreated).

Proper way to do it
function startQuiz()
	local answered = {} -- we define answered outside of the loop so it exists during all iterations
	local correct = 0

	for i = 1, #questions do
		-- Generate a random question that hasn't been answered yet
		local r

		repeat
			r = questions[math.random(#questions)]
		until not answered[r]

		-- Fetch question data
		local answer, options, points = questions[r][1], questions[r][2], questions[r][3]

		local choice

		-- We will assume the following occured:
		-- Display question

		for i=1, #options do
			-- Display options
		end

		-- Record choice (assuming choice is set)
		if choice == answer then
			correct = correct + 1
		end

		answered[r] = true
	end

	return math.floor((correct/#questions) * 100)
end