Need help concatenating a string and a number into an existing table

  1. What do you want to achieve? Keep it simple and clear!
    I am trying to concatenate a string and a number, and have it refer to an existing table when called on.

  2. What is the issue? Include screenshots / videos if possible!

local Quest1 = {
	
	["Title"] = "Fist",
	["Task"] = {"Gain 20 Strength", 20, "Strength"},
	["Reward"] = 100
	
}

for Value = 1,36 do
		
	if QuestNumber.Value == Quest then
						
		QuestAssign = ("Quest"..Value)
			
		print(QuestAssign)
			
	end
		
end

Later on in the script, I have the following line of code which is giving me an error message saying: ServerScriptService.Quest:565: invalid argument #1 to ‘pairs’ (table expected, got string)

for _, Value in pairs(QuestAssign) do
			
	if _ ~= "Task" then
				
		Quests:WaitForChild("Quest".._).Value = Value
				
	else
				
		Quests:WaitForChild("QuestTask").Value = Value[1]
		Quests:WaitForChild("QuestObjective").Value = Value[2]
		Quests:WaitForChild("QuestStatistic").Value = Value[3]
				
	end
			
end

YOU ARE USING THE WRONG CATEGORY

But i’ll continue anyways

See this part of code? What you are doing is setting the QuestAssign value to a string value, not a table.

Do you know how I could set it to a table?

I need to know some things first, can you please reply to this post with the value you’re printing in output?
I need to know what the value is.

The value the output returns is Quest1

I see what you are trying to do! What you can do is:

  1. Make a dictionary of all the quests like so:
local Quests = {

}
  1. Then add an index for each quest like so:
local Quests = {
[1] = {
     ["Title"] = "Fist",
	 ["Task"] = {"Gain 20 Strength", 20, "Strength"},
	 ["Reward"] = 100}
[2] = {blablabala} -- you continue here with other quests you want to add
}

Then you index the Quests table with the quest value, so:

local Quests = {
[1] = {
     ["Title"] = "Fist",
	 ["Task"] = {"Gain 20 Strength", 20, "Strength"},
	 ["Reward"] = 100}
[2] = {blablabala} -- you continue here with other quests you want to add
}
for Value = 1,36 do
		
	if QuestNumber.Value == Quest then
						
		QuestAssign = Quests[Value]
			
		print(QuestAssign)
			
	end
		
end

Thank you so much, this worked!

1 Like

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