I made a table for a quest system, and for some reason, the title was set to “1”. Heres my script:
local quest =
{
["Title"] = "Kill the zombies",
["Task"] = "Kill the zombies", 2,
["Reward"] = 100
}
prompt.Triggered:Connect(function(player)
local info = player:FindFirstChild("QuestInformation")
if info then
for i, v in pairs(quest) do
if i ~= "Task" then
info:WaitForChild("Quest"..i).Value = v
end
end
end
end)
The value inside quest information should be the value of [“Title”], [“Task”], and [“Reward”], but instead its set to a number(not reward). Heres the error, can someone help?
I believe I see the problem. You have your “quest” table formatted incorrectly.
You have:
local quest =
{
["Title"] = "Kill the zombies",
["Task"] = "Kill the zombies", 2, -- this is the problem area
["Reward"] = 100
}
Notice that “2” with no key. Since you have this formatted like this, Lua gets confused and can’t determine if it should interpret the table as a dictionary with keys or an array with numerical indexes.
To fix this, you could do something like:
local quest =
{
["Title"] = "Kill the zombies",
["Task"] = {"Kill the zombies", 2}, -- convert this value to a table instead.
["Reward"] = 100
}