Hello, I am making a trivia game, and I want to know how to find a table in a table. I tried doing it but it gives me attempt to index nil with ‘answers’. Can someone help? Here is my current code:
--Module script
local data = {
{
question = "Name an item a multi-millionare would buy",
answers = {"Yacht", "Superyacht", "Megayacht", "RealEstate", "Lamborghini", "Bugatti", "House", "Home", "Mansion", "PrivateJet", "Chef", "Maid"},
},
{
question = "Name a country in Eastern Europe",
answers = {"Russia", "Ukraine", "Belarus", "Romania", "Moldova", "Finland", "Estonia", "Latvia", "Lithuania"},
}
}
return data
--server script inside another script inside server script service
local Status = game.ReplicatedStorage.Status
local data = require(script.Parent.Parent["Questions/Answers"])
local Question = Status.Value
local plrs = {}
game.ReplicatedStorage.SendAnswer.OnServerEvent:Connect(function(player,answer)
local StepsFolder = workspace.StepsFolder
local questionnum = Status.Value
local answerz = table.find(data[answer])
if table.find(data[questionnum].answers, answer) then --Keeps giving me error here: attempt to index nil with 'answers'
print("Answer found!")
local length = #answer
string.lower(answer)
for i = 1,length do
local step = Instance.new("Part")
step.Parent = StepsFolder
step.Anchored = true
step.Color = Color3.new(0.901961, 1, 0.576471)
step.Name = "testingStep"
step.Size = Vector3.new(5,1,5)
step.Position = player.Character:FindFirstChild("HumanoidRootPart").Position - Vector3.new(0, 2, 0 )
if i == length then
game.ReplicatedStorage.TweenTransparency:FireClient(player,length)
end
end
end
end)
local table1 = {
{"Example"};
{"Example2"};
}
--Since there are 2 tables inside this table, we can refer to the table using an index.
print(table1[1][1]) -- This would print out "example"
print(table1[2][1]) -- This would print out "example2" since it is referring to the second index of table1
Thank you, but I already have a random question generator, what I am asking is how would I find if the answer matches up with the players answer. Like this picture above ^^