Hello, I am making a answer checker for my game and then in the for loop on line 14: for i,x in pairs() it errors on attempt to call number value. Can someone help? Here is my current code:
for i, v in pairs(data) do
local new = string.lower(answer)
if v.question == Status.Value then
for i, x in pairs(v.answers) do
if new == x then
print(answer.."True")
end
if new == x then
local sound = script.AnsweredSound:Clone()
sound.Parent = player.PlayerGui
sound:Play()
local length = #answer
Which line errors on your script?
This means x.answers is a number, not a table, try checking your other scripts.
But it is a table. This is the module script:
local data = {
[1] = {
question = "Name an item a multi-millionare would buy",
answers = {"yacht", "super yacht", "mega yacht", "real estate", "lamborghini", "bugatti", "house", "home", "mansion", "private jet", "chef", "maid", "butler"},
},
[2] = {
question = "Name a country in Eastern Europe",
answers = {"russia", "ukraine", "belarus", "romania", "moldova", "finland", "estonia", "latvia", "lithuania"},
}
}
Are you sure it errored on that line? The error doesn’t seem to fit with that line.
I am 100% sure it errored on that line.
The error should only appear if you’re doing this:

Could you screenshot the output with the error and the script?

Edit: here is the entire script which contains line 45 if you want.
local Status = game.ReplicatedStorage.Status
local data = require(game.ReplicatedStorage["Questions/Answers"])
local Question = Status.Value
local StepsFolder = workspace.StepsFolder
local plrs = {}
local params = RaycastParams.new()
params.FilterType = Enum.RaycastFilterType.Whitelist
local function CheckAnswer(player,answer)
for i, v in pairs(data) do
local new = string.lower(answer)
if v.question == Status.Value then
for i, x in pairs(v.answers) do
if new == x then
print(answer.."True")
end
if new == x then
local sound = script.AnsweredSound:Clone()
sound.Parent = player.PlayerGui
sound:Play()
local length = #answer
for i = 1,length do
task.wait(0.1)
local step = Instance.new("Part")
step.Parent = StepsFolder
step.Anchored = true
step.Color = Color3.new(0.901961, 1, 0.576471)
step.Name = "Step"
step.Size = Vector3.new(5,1,5)
params.FilterDescendantsInstances = {StepsFolder,workspace.Game}
local rayres = workspace:Raycast(player.Character:FindFirstChild("HumanoidRootPart").Position,Vector3.new(0,-8,0),params)
step.CFrame = rayres.Instance.CFrame + Vector3.new(0,1,0)
if i == length then
game.ReplicatedStorage.TweenTransparency:FireClient(player,length)
end
end
end
end
end
end
end
game.ReplicatedStorage.SendAnswer.OnServerEvent:Connect(function(player,answer)
CheckAnswer(player,answer)
end)
Like a screenshot with your entire screen, including the output.
Including with the script or the actual gameplay?
Just a screenshot of your entire screen with the script and the output.
I can’t really do that, since my game is 2 player only it requires 2 players and opening scripts in the team test just shows its blank.
try replace v.answers with v[2]
I have a random question generator so I can’t rlly do that either.
Random generator replacing the names of the tables inside the table?
v[2] will index the second value in the table which is answers
1 Like