Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to index a value of a datastore loaded dictionary that is the same as another dictionary? SOLVED

Asked by
aredanks 117
4 years ago
Edited 4 years ago

I have a dictionary that is created like this which is given default values with newly joining players and will also be saved with any changes to it like this. (dictlist just looks like an empty table)

dictlist[player.Name] = {
        Coins = 10,
        Pts = 0,
        StringLetter = "J"
    }

dictload is just dictlist being saved when the player leaves as a separate dictionary

for i, v in pairs(dictload) do
            --print(statstosave[plr.Name][tostring(v)].." = "..v)
            if dictlist[plr.Name][v] then
                dictlist[plr.Name][v] = v
                print("data exists")
            end
        end

Data saves the dictlist also by replicating this dictionary (as any changes to it will occur and it will replicate those changes) but it never loads because dictlist[plr.Name][v] does not exist (nil) .

For example in the loop, I would like to index ["Coins"] but with the for pairs loop, using either v or tostring(v) returns only nil yet the loaded dict (print checked) actually has ["Coins"] in it with a given value.

I am assuming that I am not correctly indexing the other dictionary's values although the dictionary has the equivalent variables using this method, I am asking for an answer that solves this problem.

Solution: Copy loaded dictionary via a different way/replace dictionary with loaded dictionary (used replacement, I just set it as the loaded dictionary)

Answer this question