The quests that exist go like quest1, quest2 right now but eventually they will have unique names. How do I make this code into a for loop so I don’t have to write out the connections for every single quest.
I cant assure you this works, but it can give you an idea of what you need to do
Alright so if I understand correctly, you don’t want to repeat the same lines over and over again,
but in order for this to work you’ll need to change some things.
Alright in this example below i changed quite some things, not everything you have in your screenshot is included, but I think you can add those things yourself
local Names = {
"Quest.Quest1",
"Quests.Quest2"
} -- Put the names here
local QuestAmount = #Names -- gets length of the Names table
local function MakeConnections()
for i = 1, QuestAmount do
local Name = Names[i] -- Gets the name
QuestJournal[i] = replica_data.Quests:GetChildren()[i]
--^^ assuming this line above gets a folder in replicated storage, use getchildren
replica:ListenToChange({Name}, function(new_value)
QuestJournal[i] = new_value -- in order for this to work with the for loop, you need to change things
end)
end
end
Alright so as i said you need to make some changes, so what do you need to change?
Well first of make a table called Names (see in example above)
, so this line can work:
replica:ListenToChange({Name}, function(new_value)
Okay so in order to acces the questjournal using a for loop, you will also need to change it.
So, Assuming questjournal is a table that looks something like this:
local QuestJournal = {
Quest1 = -1,
Quest2 = -1
}
You’ll need to change it to this
local QuestJournal = {
[1] = -1,
[2] = -1
}
And lastly this line:
QuestJournal.Quest1 = replica_data.Quests.Quest1
I don’t know what this means, but i’m assuming this is a folder in replicated storage which stores quest values.
This line(that i changed) only works if the folder only stores values, that are: quest1, quest2 etc, and not other values
If you have any questions, i will respond whenever i can