One datastore is working but the other isnt?

i did, I do it every time I test

local DataStoreService = game:GetService("DataStoreService")

local PlayerData = DataStoreService:GetDataStore("MoneyDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = 0
	money.Parent = leaderstats

	local totaltrash = Instance.new("IntValue")
	totaltrash.Name = "Trash"
	totaltrash.Value = 0
	totaltrash.Parent = leaderstats

	local Backpack = Instance.new("IntValue")
	Backpack.Name = "BackpackTrash"
	Backpack.Value = 0
	Backpack.Parent = leaderstats
	
	local data
	
	local sucess, errormessage = pcall(function()
		data = PlayerData:GetAsync(player.UserId)
	end)
	
	if sucess and data ~= nil then
		for name , value in pairs (data) do
                    player.leaderstats[name].Value = value
                end
	else
		print("There was an error getting your data")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
        
        Local tableToSave = {}

        For i,v in pairs(player.leaderstats:GetChildren())do
tableToSave[v.Name] = v.Value
end
	local sucess, errormessage = pcall(function()
		PlayerData:SetAsync(player.UserId,tableToSave)
	end)
	if sucess then
		print("Data Successfully Saved!")
	else
		print("Error Saving Data.")
		warn(errormessage)
	end
	

The script may look different but why not give it a try

this only has the money data store

hes creating a table for the leaderstats and putting it into one datastore

I create a table that store all values and save the table @Arthur_Grandwell said so

Edit:I write this on phone sooo someone might have to adjust the code to make it better

Can u tell me which line was it

it doesnt save money but it saves total trash and backpack trash but i dont want it to save backpack trash

Ooops my bad

Change this

player.leaderstats[name].Value = value

To this

player.leaderstats[name] = value

That will do

And for bacpacktrash just set it to 0 or whatever after getting the data

now theres this error

My bad again

player.leaderstats[name].Value = value

Edit : does it save the data?

it saves everything but the money

no errors or any warns on the prints

Can u show me ur current script
Also try print the data after you save it and get it

now its not saving any data

local DataStoreService = game:GetService("DataStoreService")

local PlayerData = DataStoreService:GetDataStore("MoneyDataStore")

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local money = Instance.new("IntValue")
	money.Name = "Money"
	money.Value = 0
	money.Parent = leaderstats

	local totaltrash = Instance.new("IntValue")
	totaltrash.Name = "Trash"
	totaltrash.Value = 0
	totaltrash.Parent = leaderstats

	local Backpack = Instance.new("IntValue")
	Backpack.Name = "BackpackTrash"
	Backpack.Value = 0
	Backpack.Parent = leaderstats

	local data

	local sucess, errormessage = pcall(function()
		data = PlayerData:GetAsync(player.UserId)
	end)

	if sucess and data ~= nil then
		for name , value in pairs (data) do
			player.leaderstats[name].Value = value
		end
	else
		print("There was an error getting your data")
		warn(errormessage)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)

	local tableToSave = {}

	for i,v in pairs(player.leaderstats:GetChildren())do
		tableToSave[v.Name] = v.Value
	end
	local sucess, errormessage = pcall(function()
		PlayerData:SetAsync(player.UserId,tableToSave)
	end)
	if sucess then
		print("Data Successfully Saved!")
	else
		print("Error Saving Data.")
		warn(errormessage)
	end
end)

Try print name and value in for loops statement

how would i do that, and should i do datastore tables isntead?

for name , value in pairs (data) do
                  print(name,value)
	player.leaderstats[name].Value = value
		end

Try that and see if there is data

yup
image

So the problem is the data didnt save??