DataStore2: Tables not saving (no errors in console)

Hi, I recently switched from using an external database to using DataStore2 but have been having issues with saving a table. So from the picture, as you see I am trying to update the table but in the actual database, nothing is changing. If you know a solution to this, let me know.

		local dsWins = DataStore2("Wins", player)
		local dsDeaths = DataStore2("Deaths", player)
		local dsDiamonds = DataStore2("Diamonds", player)
		local dsItem = DataStore2("Item", player)
		local dsSecretPass = DataStore2("SecretPass", player)
		local dsUserTags = DataStore2("UserTags", player)
		
		local getWins = dsWins:Get(0)
		local getDeaths = dsDeaths:Get(0)
		local getDiamonds = dsDiamonds:Get(0)
		local getItem = dsItem:Get("None")
		local getSecretPass = dsSecretPass:GetTable({S1 = { XP = 0 }})
		local getUserTags = dsUserTags:GetTable({Equipped = "None", Owned = {}})
		
		local leaderstats = Instance.new("Folder")
		leaderstats.Name = "leaderstats"
		leaderstats.Parent = player

		local Wins = Instance.new("IntValue")
		Wins.Name = "Wins"
		Wins.Parent = leaderstats
		Wins.Value = getWins

		local Deaths = Instance.new("IntValue")
		Deaths.Name = "Deaths"
		Deaths.Parent = leaderstats
		Deaths.Value = getDeaths

		local extraleaderstats = Instance.new("Folder")
		extraleaderstats.Name = "extraleaderstats"
		extraleaderstats.Parent = player

		local Diamonds = Instance.new("IntValue")
		Diamonds.Name = "Diamonds"
		Diamonds.Parent = extraleaderstats
		Diamonds.Value = getDiamonds
				
		local SecretPass = Instance.new("Folder")
		SecretPass.Name = "SecretPass"
		SecretPass.Parent = player

		local XP = Instance.new("IntValue")
		XP.Name = "XP"
		XP.Parent = SecretPass
		XP.Value = getSecretPass.S1.XP
		
		local UserTags = Instance.new("Folder")
		UserTags.Name = "UserTags"
		UserTags.Parent = player

		local Equipped = Instance.new("StringValue")
		Equipped.Name = "Equipped"
		Equipped.Parent = UserTags
		Equipped.Value = getUserTags.Equipped
	
		local Owned = Instance.new("Folder") 
		Owned.Name = "Owned"
		Owned.Parent = UserTags
		
		local jsonString = getUserTags.Owned
		local tableJSON = HttpService:JSONDecode(jsonString)
		
		if type(tableJSON) == "table" then
			for k, v in pairs(tableJSON) do
				local Data = Instance.new("StringValue")
				Data.Name = k
				Data.Value = v
				Data.Parent = Owned
			end
		end
		
		game.ReplicatedStorage.TagsData:FireClient(player, "refresh")

		local tagLevels = {
			[5] = "ShadowMaster",
			[10] = "SupremeOverlord",
			[15] = "EmberHighlord",
			[20] = "MysticEnforcer",
			[25] = "SpectralOverlord",
			[30] = "MythicalLegend"
		}

		local SecretPassLvl = math.floor(XP.Value / 25)

		local function setPlayerTag(tag)			
			dsUserTags:Set({Owned = {[tag] = "Owned"}})
			
			local tagdata = Instance.new("StringValue")
			tagdata.Name = tag
			tagdata.Value = "Owned"
			tagdata.Parent = Owned
			
			game.ReplicatedStorage.TagsData:FireClient(player, "refresh")
		end

		for level, tag in pairs(tagLevels) do
			if SecretPassLvl >= level then
				if not Owned:FindFirstChild(tag) then
					setPlayerTag(tag)
				end
			end
		end

1 Like

:sob:

I don’t want to be rude but please fix that code before posting it on devforum.

local data = {
  Owned = {[tag] = 'Owned'}
}
-- or even better just make data.Owned an array please
local data = {
  Owned = {tag}
}

Ok I haven’t used DataStore2 but does :Set() add a new table to the certain key or does it just overwrite it?

If I am sure it adds a new table to the certain key

I have updated the script so that yall understand more what’s going on

I found the issue, so by mistake I had something overwriting the table that’s why it was not getting updated.

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