Saving data script not working

Hey!

My script for saving the players cards aren’t working. The cards are just string values in a folder in the player.

Saving part of script:

local function SaveAllCards(player, cards)
	
	local key = player.UserId

	local data = {}
	
	for i,v in pairs(cards) do
		
		table.insert(data, v.Value)
		
	end
	
	local success, errorMessage = pcall(function()
		CardsStore:SetAsync(key, data)
	end)

	if success then
		print("Success Saving Equipped Cards")
	else
		warn(errorMessage)
	end
	
end

Loading part of script:

local function LoadAllCards(player, cardsFolder)
	
	local key = player.UserId

	local data
	local success, errorMessage = pcall(function()
		data = AllCardsStore:GetAsync(key)
	end)

	if success then
		
		for i = 1, #data, 1 do
			
			local Card = Instance.new("StringValue", cardsFolder)
			Card.Name = data[i]
			Card.Value = data[i]
			
		end
		
	else
		warn(errorMessage)
	end
	
end

I believe the problem is with loading. The table in saving prints all the values but “data” in loading is returning nil

Are CardsStore and AllCardsStore the same datastore?

1 Like

No their not. This was the solution, thank you!

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