Problems with a table

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?

It wouldnt hurt to print the quest table, I dealt with this earlier this week, Ill see if I can guide you

I tried printing and it gave me a number as well

wut? did you do print(quest)

also try this:

quest={}

quest["Title"]= "Kill the zombies"

--do the same for the rest

Now it just says

Infinite yield possible on 'Players.catxkdb.QuestInformation:WaitForChild("QuestTaskNumber")'

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 
	}
1 Like

Thanks! (character limit) (more character limit)

1 Like