Datastore GetAsync gives me "Instance"?

I made a quick save and load function for my player class and in the save function everything seems to work serializedData looks like this {"stats":{"health":100,"damage":5,"shield":0,"xp":0,"level":1}} (which is valid JSON according to jsonlint) however when I load the data serializedData is giving me Instance.

	function self.save()
		print("Saving")
		local data = {
			stats = stats.serialize()
		}
		local serializedData = game:GetService("HttpService"):JSONEncode(data)
		print(serializedData)
		playerDataStore:SetAsync(userId, serializedData)
	end
	
	function self.load()
		print("Loading")
		local success, serializedData = playerDataStore:GetAsync(userId)
		if success then
			print("loaded data")
			print(serializedData)
			local data = game:GetService("HttpService"):JSONDecode(serializedData)
			
			stats = Stats.new()
			stats.load(data.stats)
		else
			print("failed to load data")
		end
	end

Take a look at the API.

Your first value “success” is your data, and the next is the DataStoreKeyInfo instance.

You forgot to wrap this in a pcall. It should be:

local success, serializedData = pcall(playerDataStore.GetAsync, playerDataStore, userId)

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