This is my first post on scripting support as I cannot find anything online regarding my issue. Please tell me if I have done something incorrect!
-
What do you want to achieve? Keep it simple and clear!
I would like DataList to not have every index be overwritten (I explain better below) -
What is the issue? Include screenshots / videos if possible!
Everytime I go to insert a value (DataFromDS) into DataList, it returns DataList with every index the value that was just inserted (look at the code to see what I mean, I don’t know how to explain it well). If I assign literally anything else (like unique strings, integers, or even the DataID itself, or just a singular value of DataFromDS) to DataList[DataID] it works completely fine. I’ve even tried using the ‘i’ value instead of DataID and it still did not work.
This shows that the data is unique
Each DataID returns a different timestamp
Iterating through each value in the table after all values have been set
Each index in the table returns the exact same timestamp (this should not be the case)
Assigning a unique value directly to DataList[DataID] works
This is not the behavior I want, as I want DataList[DataID] to be the entire table of data instead of just the one value.
- What solutions have you tried so far? Did you look for solutions on the Developer Hub?
- I have verified DataIDsList has unique ids
- I have verified DataModel:GetDataFromID(DataID) returns the correct data (as in returns different data depending on DataID provided).
- I have tried inserting values into DataList using different methods like table.insert(), indexing values directly DataList[DataID] (like in the example below)
- I have tried inserting different values into DataList like the DataID directly and it worked correctly. It’s just when inserting a data in the format I need to into DataList - it sets every value to the table that was just inserted.
I have modified the following code (the code in screenshots was also edited), though the logic executes pretty much the same as the code in-game.
local DataModel = require(game:GetService("ServerScriptService"):WaitForChild("Models"):WaitForChild("ThreadModel"));
local DataList = {};
local DataIDsList = {1,2,3,4,5,6};
-- Loops through DataIDsList and **is SUPPOSED TO** assign DataList[DataID] to the DataID's data
for i, DataID in pairs(DataIDsList) do
local DataFromDS = DataModel:GetDataFromID(DataID);
-- This line sets DataFromDS in the format:
--[[
DataFromDS = {
UserID = 12345;
SomeValueSetByPlayer = "This is a title",
...
}
]]
DataList[DataID] = DataFromDS;
end
print(DataList)
--[[
Prints:
DataList = {
[1] = {
UserID = 12345;
SomeValueSetByPlayer = "This is a title 1";
...
};
[2] = {
UserID = 12345;
SomeValueSetByPlayer = "This is a title 1";
...
};
[3] = {
UserID = 12345;
SomeValueSetByPlayer = "This is a title 1";
...
};
-- Exact duplicates of the last value that was inserted
}
Should print (something like):
DataList = {
[1] = {
UserID = 12345;
SomeValueSetByPlayer = "This is a title 1";
...
};
[2] = {
UserID = 2425234;
SomeValueSetByPlayer = "This is a different title";
...
};
[3] = {
UserID = 2133624;
SomeValueSetByPlayer = "This another unique title";
...
};
-- Unique data for each
}
]]
Why is the table DataList having EVERY value set to DataFromDS when only DataList[DataID] (DataList indexed at DataID) should be set to DataFromDS?
Thanks in advance, I hope it’s something really simple that I completely missed because I’m tired