Pairs loop in a dictionary table returns value in index, and nil in value

I’m working on a game and I decided to add a script to help convert data for a player whenever I add a new variable to the average data every person has.

This is the function to get the basic data if you have no data and you’re new:

And this is the code that detects either no data, data existing but outdated and data:

(This code grabs another plain table and replaces all the values inside the new table with the ones that already exists in the player’s existing but outdated data, and the TABLEVERSION variable is how it detects outdated data.)

When this data is converting, what it prints each time is the index and value of the player’s existing but outdated data table and this is what it returns:
In the index position, we have the value and in the value position we always have nil.

This has been breaking my game for some time and I need serious help.

hmm, I’m not sure why you’re using e as the index for the tables.
within’ the pairs loop, that if statement can you change it to this:
if data[i] and type(data[i]) == type(newtable[i]) then
newtable[i] = data[i]

Well you can’t access data[e] since e is the value at the key ‘i’.
To fix this, you can just replace




That would end up overwriting any existing data with a blank table since the pairs loop is with a new table instead of one pulled from datastore.
So using data[i] in this case should work.

Thank you so much for this help!

(P.S: This code was used in another game of mine and works exactly the same way your solution does now so I’m confused as hell like you are.)

I would just pay closer attention to what variables you’re using as indexes.
using print is a great way to debug lol.

I have another quick thing I need to solve,

When the data converts, I forgot to exclude not updating the TABLEVERSION with the old one from the player’s outdated data

How can I exclude this?
Because this doesn’t wanna work:

instead of data[i] you just do i in this case. i ~= "TALBEVERSION"

It works, Thank you for your dedicated time you put into helping me. :+1:

No problem, hopefully everything is smooth sailing from there lol.