Currency data store system isn't working

So recently, I wanted to reuse code from another game that I coded a currency data store system for. I renamed the assets to the new currency name, and now it doesn’t work anymore. And the output is saying treats is not a valid member of folder Here’s the code:

local DataStoreService = game:GetService("DataStoreService")

local DataStoreName = DataStoreService:GetDataStore("myDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local stats = Instance.new("Folder")
	stats.Name = "leaderstats"
	stats.Parent = player
	
	local coins = Instance.new("IntValue")
	coins.Name = "Treats"
	coins.Parent = stats
	
	local data
	local success, errormessage = pcall(function()
		data = DataStoreName:GetAsync(player.UserId.."-treats")
		coins.Value = data
	end)
	
	if success then
		print("Data Loaded")
	else
		print("Error")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errormessage = pcall (function()
		DataStoreName:UpdateAsync(player.UserId.."-treats",function(old)
			local newvalue1 = old
			newvalue1 = player.leaderstats.treats.Value
			return newvalue1
		end)
	end)	
	
	if success then
		print("Data has been saved")
	else
		print("Error")
		warn(errormessage)
	end
end)
2 Likes

You called the IntValue “Treats” which is case sensitive

2 Likes

Oh that’s why. Thanks for your help. :slight_smile:

2 Likes