DataStore :GetAsync Data Returning nil

I am currently attempting to save a table, but when I :GetAsync, the variable, data, returns nil. The data I am saving is not nil, as there is a print() line there and it prints the correct data. I checked if I had API services on, I do, and I don’t know what could be wrong. Here is the code.
In the second function, KitsFolder returns as a filled table.

game.Players.PlayerAdded:Connect(function(player)
	
	local success, data = pcall(function()
		MainDataStore:GetAsync(player.UserId..KitsKey)
	end)
	
	if not success then
		warn("Saving failed for "..player)
	end

	local KitsFolder = Instance.new("Folder")
	KitsFolder.Name = "KitsFolder"
	KitsFolder.Parent = player
	
    if data then
        print(data)
    end

end)

game.Players.PlayerRemoving:Connect(function(player)
	
	local Statistics = player:WaitForChild("Statistics")  
	
	local KitsTable = ScanFolder(player.KitsFolder,{})
	print(KitsTable)
	
	local success, data = pcall(function()
		MainDataStore:SetAsync(player.UserId..KitsKey,KitsTable)
	end)
	
	if not success then
		warn("Saving failed for "..player)
	end
	
end)
1 Like

I realized that the second variable is the error message and not the data !

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