Saving a Dictionary with DataStores

Hello, I’m Matt, I’m trying to make a Quest system (which is working) but I’m trying to add DataStores so it saves your progress, basically there’s a boolvalue with the questName and your progress, and I’m trying to get it to save the boolvalue and the progress to load in!

Currently it’s not working, I’ve tried printing what I get from the dataStore but it’s always a blank table!
errorMsg

I’ve tried searching on Google and DevForum on saving Dictionaries, but nothing has worked so far!

Data Loading:

 		local currentQuests = player:WaitForChild("CurrentQuests")
		
		local questsData = nil
		
		pcall(function()
			questsData = questsDataStore:GetAsync(player.UserId.."-quests")
		end)
		
		if questsData ~= nil then
			for i, questName in pairs(questsData) do
				if questAssets:FindFirstChild("Quests"):FindFirstChild(questName) then
					
					local cloneQuest = questAssets:FindFirstChild("Quests"):FindFirstChild(questName)
					cloneQuest:FindFirstChild("Current").Value = tonumber(i)
					cloneQuest:Clone().Parent = currentQuests
					
					quests[questName](player)
					
				end
			end
		end

Data Saving:

	local questsTable = {}
	
	for _, quest in pairs(player:WaitForChild("CurrentQuests"):GetChildren()) do
		if quest and questAssets:WaitForChild("Quests"):FindFirstChild(quest.Name) then
			
			questsTable[quest.Name] = {}
			table.insert(questsTable[quest.Name], quest:WaitForChild("Current").Value)
			
		end
	end
	
	pcall(function()
		questsDataStore:SetAsync(player.UserId.."-quests", questsTable)
	end)

Thank you for reading, if you have anymore questions please comment them

Surely this is not an issue that someone should have to encounter. I have not seen this but I suggest using JSON Encoding. Here’s the API documentation for that, but its pretty self explanatory.

API

1 Like

That’s not a blank table. You need to press the little triangle to display it’s contents in the output…

2 Likes

It takes me to the line where I print the questData

You’ve got to click the arrow itself.

The little triangle is supposed to show the contents of the table. Try restarting studio and running it again

▶ {...}  -  Server - Script:2
▼  {
                    [1] = "entry01",
                    [2] = "entry02"
                 }  -  Server - Script:2

Oh I see, that’s pretty interesting!

tab

1 Like

Sorry, it didn’t work, but I’m happy you atleast tried, and I appreciate you for it!

Inside the tables is [1] = 0

I’m just gonna type this because of the limit!

When it saves the progress it does say one!

It has to be the way of me loading it in

I’ve tried a lot of things, still doesn’t work!

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)