I’m trying to make a script that gets a table of 3 random quests from the servers through a remoteevent and then uses the information to edit a GUI. The function is as such:
RS.Quests.GetQuests.OnClientEvent:Connect(function(QuestsData)
local Template = dailyquests:WaitForChild("QuestTemplate")
print(QuestsData)
local QuestList = QuestsData.Quests
for i, questData in ipairs(QuestList) do
--...
For example, when I run the code, print(QuestsData)
outputs:
18:56:40.659 ▼ {
[“153978678”] = ▼ {
[1] =
{…},
[2] =
{…},
[3] =
{…}
}
}
My issue is with retrieving the QuestsData. I have tried to use QuestsData.Quests
as well as QuestsData[2]
to reference the subtable, but they all output nil
. With that, how can I edit the code so that the code correctly indexes the table of Quests?
You should probably include more of the script, because there’s not that much context what everything is, and some of the stuff you refer to isn’t in your snippet of script.
I can see something that, might be something though:
if that print thing is QuestData, it looks like its a table with playerID’s, and then each playerID has its own table where I think you were trying to refer to. So, maybe QuestData.[PlayerID][1], or something? If that wasn’t your issue, can you include way more of the script so I can be more of a help?
From the look of this table, I’d say you’d have to access the quests with the format:
QuestsData[tostring(player.UserId)][1]
QuestsData[tostring(player.UserId)][2]
QuestsData[tostring(player.UserId)][3]
Your QuestsData table is a dictionary with only one entry, for which the key appears to be your Roblox UserId converted to a string. The value is an array with 3 elements, presumable each being a table for a quest. So your quest array, for your user id specifically, is the table QuestsData["153978678"]
which has your 3 quests with indices 1, 2, and 3.
1 Like