Datastore Issue - Incorrect Data being Loaded & Saved

I want to load and save the values of a Cosmetics Shop data system I’ve made. Specifically, I want both the Bought and Unlocked pieces of data to load in and save properly. Yet, I get this error message:

I print the dataTable to show that, in fact, there is no Bought in the dataTable. So, I see that, but why is it like that? Nowhere in my code do I have just one value being saved. I used to in an old get_saveFile3_DataTable_FromDataStore, but I changed the name of the data store. Shouldn’t that make it a new slate? There’s a comment in the code I provide below that shares the old dataStore Names/strings. No matter what version I use, new or old, I seem to still have this same error/issue.

Maybe the data from the old data store is being saved to the new one. But, I don’t think I do that in my code either. So, I have no idea why the Cosmetics are only having one value.


I’ve reread the docs about datastores and some posts on the forum; I can’t find the solution. Maybe it’s something to do with Cache? I don’t think it is, but I can update this post after I try that.


The code is too long to simply copy and paste into a code block. The devforum has a character limit. Not sure which file format is best for people, so I’ll put whatever Roblox lets me. It’s all the same code, just different export formats.

DataStoring_ServerScript__Main.lua (72.4 KB)
DataStoring_ServerScript__Main.rbxmx (71.7 KB)
DataStoring_ServerScript__Main.rbxm (12.6 KB)

It looks like the output is printing out a table with numbered indices, not keys. My guess is that there is a problem with your saving system so that your data values are being saved but not their names, so your script errors when it cannot find the key. I skimmed your code and it looks like you are trying to save a dictionary to a Datastore, which does not work. The documentation on JSON explains how to turn dictionaries into JSON objects which can be saved to datastores. When the data is loaded, the JSON can be decoded into a dictionary which should have all the values you’re looking for. Hope this helps!

1 Like

I was saving data based on a table that had strings as the children. I changed the Strings to Variables by making them CamelCase and getting rid of the quote marks. After doing that, the system is now working.

Your mention/questioning of how the saving system was working got me to question how other parts of data saves in my game, the ones that are working. That made me try changing the Strings to Variables. So, even if the JSON thing didn’t work out -I felt that would be complicating things-, your reply helped a bunch.

In short, using Strings doesn’t work for data storing with a dictionary, but using Variables does work.

Thanks!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.