Troubles saving dictionary (datastore2)

  1. What do you want to achieve?
    I want to be able to save my dictionary.
  2. What is the issue?
    whenever I save it, it doesnt actually get saved for some reasons.
  3. What solutions have you tried so far?
    Saving currencies and tables work completly fine but this didnt work.


I have tried removing [v.PetID.Value] and it worked fine but I want it to save even like that because thats essential for my pet data

local DS2 = require(game.ServerScriptService.DataStore2)
DS2.Combine("DATA2", "Pets5")
	local PetsData = DS2("Pets5", player)
	local playergui = player:WaitForChild("PlayerGui")
	local Inventory = playergui:WaitForChild("Main").PetInv.Inventory
	local playerid = player.UserId
	local DataDictionary = PetsData:Get(nil)
	if DataDictionary ~= nil then
		for i, v in pairs(DataDictionary) do 
		local PetSaveDictionary = {}
		for i, v in pairs(player.Pets:GetChildren()) do
			PetSaveDictionary[v.PetID.Value] = {
				["Mobility"] = {Value = v.Mobility.Value};
				["Name"] = {Name = v.Name};
				["Rarity"] = {Value = v.Rarity.Value};
				["Equipped"] = {Value = v.Equipped.Value};
				["Level"] = {Value = v.Level.Value};
				["Locked"] = {Value = v.Locked.Value};
				["Multi1"] = {Value = v.Multi1.Value};
				["Multi2"] = {Value = v.Multi2.Value};
				["PetID"] = {Value = v.PetID.Value};
				["Type"] = {Value = v.Type.Value};
				["XP"] = {Value = v.XP.Value};

You have to put tostring() or tonumber() around all your table values.

This is what you have:

["Type"] = {Value = v.Type.Value};
["XP"] = {Value = v.XP.Value};

This is what you need:

["Type"] = {Value = tonumber(v.Type.Value)};
["XP"] = {Value = tonumber(v.XP.Value)};

that didnt change anything though, when I save my dictionary the whole thing isnt saving not just the values, when I tried the same thing but removed [v.PetID.Value] it actually worked
tonumber or tostring wont really change anything since v.Type.Value is a number and v.Name is a string so that will pretty much change nothing

This might just be a DataStore2 issue and not an issue related to your script. Have you tried ProfileService? It isn’t just for saving player data and works wonders.

ProfileService is having some issues atm and I’d rather not use it, I’m learning datastore2 rn and I really cannot figure out why that wasnt working

I don’t think there are any new recorded errors currently.

Anyways I can no longer help as I don’t know anymore, I hope you figure it out though!

solved it, I had to do some experiments and I finally figured it out