Attempted to index nil with "Choices"

I’m try to make a module multiple choice system using tables but it printed out “attempted to index nil with Choices”

Here my local script:

local Module = require(script.Parent.ModuleScript)
local QuestionText = script.Parent.Frame.Question
local ButtonHolder = script.Parent.Frame.ButtonHolder
local Debounce = false


for i = 1, 2 do
	Debounce = false
	for _, Choices in pairs(Module[i].Choices) do
		local textButtonClone = game.ReplicatedStorage.TextButton:Clone()
		textButtonClone.Parent = ButtonHolder
		textButtonClone.Text = Choices
		
		textButtonClone.MouseButton1Click:Connect(function()
			if textButtonClone.Text == Module[i].Answer then
				print("You got it right")
				Debounce = true
			else
				print("Try again")
			end
		end)
	end
	repeat task.wait() until Debounce == true
end

My module script:

local module = {

	Question1 = {
		Question = "What color is a strawberry",
		Choices = {"Yellow", "Purple", "Green", "Red"},
		Answer = "Red"
	},

	Question2 = {
		Question = "What 5 + 3",
		Choices = {"8", "3", "12", "9"},
		Answer = "8"
	},

}
return module

If you guys wanna see the output here it is:

Maybe because it’s a dictionary that’s why it isn’t getting a table. I think you should just reference it like: Module[“Question”..i].Choices

My script works perfectly fine now, thank you so much.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.