Saving a Dictionary with DataStores

Couple of things…
If your testing this in studio then you should be aware that the game usually closes before it’s had time to run the player.removing code so it’s best to test DataStore saving in an actual published game or use BindToClose to save your data for testing.

What are you trying to do here:

It is likely an issue of what you are trying to store. Can you show me one of the tables inside of your dictionary expanded?

Secondly, make sure you enable studio access to API services in game settings.

It’s a module script to run the quest

I have API services enabled
tab2

When I do a bit of the quest

tab3

Run a test server with one player (don’t just click the test button), and disconnect the client. The server side window should stay open, you will be able to see if there are any errors on save. Let me know how that works.

Sorry to not have a better solution yet, but diagnosis is key

1 Like

It prints nil on line 65 which is printing the questData

Can you post an image of the entire error really quick? (Along with the line of code and encompassing code)

It doesn’t print it anymore, idk why, I didn’t change anything

Does the data work properly now?

Nope, it doesn’t, I can try a few more things but idk what to do

Oh, this may be the issue but I am not sure. You’re defining the quest completion with a table that only has one value. It would be easier (and may fix your code) to define the quest as only the number.

i.e
["Open Shop"] = 0
vs.
["Open Shop"] = {0}

If you are currently attempting to do something along the lines of:
LoadedValue = Data["Open shop"]
calling LoadedValue will return the entire table. You would need to use LoadedValue[1] to access only the number value

How would I be able to do that?

That it looks like this

	local questsTable = {
		["Open Shop"] = 0
	}

In your saving code, change
questsTable[quest.Name] = {}
to
questsTable[quest.Name] = quest:WaitForChild("Current").Value

(and remove the table.insert)

Yes it does work, but now I just need the loading system to work!

What is your issue there?

Also, is the first issue resolved?

I found another problem, when I do the quest and it turns 1 when I leave and rejoin it does go to 1 but if I leave and rejoin again it goes back to 0

Some of these issues may be related to testing in studio. Try testing in-game a few times and see if you have the same issues.

Change

for i, questName in pairs(questsData) do

to

for questName, i in pairs(questsData) do

in your loading script