Datastore SetAsync() problems

I am trying to make a system in which the data on how many wins a player has can be saved as an integer.
The problem with this is that it is not saving how I’d expect it to. I’m quite baffled as to what the output if gives me actually means.

The code for saving data:

function module:Save()
	for i, stat in pairs(self.Player.leaderstats:GetChildren()) do
		self.Data.leaderstats[stat.Name] = stat.Value
	end
	
	print(self.Data.leaderstats.Wins, type(self.Data.leaderstats.Wins))
	
	local winsDataStore = referenceModule.DATA_STORE_SERVICE:GetDataStore("WinsTest")
	
	local success, errMsg = pcall(function()
		profileDataStore:SetAsync(self.Player.UserId, self.Data)
		winsDataStore:SetAsync(self.Player.UserId, self.Data.leaderstats.Wins)
		
		print(winsDataStore:GetAsync(self.Player.UserId))
	end)
	
	print("DATA SAVE SUCCES IS: "..tostring(success))
end

The output of the code:
16:26:07.871 1 number ← print(self.Data.leaderstats.Wins, type(self.Data.leaderstats.Wins))

16:26:07.871 Disconnect from ::ffff:127.0.0.1|64454 - Studio

16:26:08.635 1 Instance - Server ← print(winsDataStore:GetAsync(self.Player.UserId))

16:26:08.635 DATA SAVE SUCCES IS: true ← print("DATA SAVE SUCCES IS: "…tostring(success))

The output above confuses me, as it says that they value of the Wins is 1, and the type is a number. However, when I save it, and print what was saved, apparently it’s value is one, and it is an instance? What does this mean?

I think if you add .Value after self.Data.leaderstats.Wins it might work

1 Like