Instances not being created

For some reason only the money instance is being created. Does anyone know why? Thanks.

local ds = dss:GetDataStore("1")


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

	playerKey = "Player_"..player.UserId
	local data = ds:GetAsync(playerKey.."data")
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local otherstats = Instance.new("Folder")
	otherstats.Name = "otherstats"
	otherstats.Parent = player

	local money = Instance.new("IntValue")
	money.Parent = leaderstats
	money.Name = "Money"
	money.Value = data.money or 0
	
	local level = Instance.new("IntValue")
	level.Parent = leaderstats
	level.Name = "Level"
	level.Value = data.level or 1
	
	local exp = Instance.new("IntValue")
	exp.Parent = leaderstats
	exp.Name = "Exp"
	exp.Value = data.exp or 100
	
	local income = Instance.new("IntValue")
	income.Parent = leaderstats
	income.Name = "Income"
	income.Value = data.income or 0
	
	local mg1 = Instance.new("IntValue")
	mg1.Parent = otherstats
	mg1.Name = "mg1"
	mg1.Value = data.mg1 or 0
	
	local mg10 = Instance.new("IntValue")
	mg10.Parent = otherstats
	mg10.Name = "mg10"
	mg10.Value = data.mg10 or 0
	
	local mg100 = Instance.new("IntValue")
	mg100.Parent = otherstats
	mg100.Name = "mg100"
	mg100.Value = data.mg100 or 0
	
	local mg1k = Instance.new("IntValue")
	mg1k.Parent = otherstats
	mg1k.Name = "mg1k"
	mg1k.Value = data.mg1k or 0
	
	local mg10k = Instance.new("IntValue")
	mg10k.Parent = otherstats
	mg10k.Name = "mg10k"
	mg10k.Value = data.mg10k or 0
	
	local mg100k = Instance.new("IntValue")
	mg100k.Parent = otherstats
	mg100k.Name = "mg100k"
	mg100k.Value = data.mg100k or 0
	
	data = {
	money = money.Value;
	level = level.Value;
	exp = exp.Value;
	income = income.Value;
	mg1 = mg1.Value;
	mg10 = mg10.Value;
	mg100 = mg100.Value;
	mg1k = mg1k.Value;
	mg10k = mg10k.Value;
	mg100k = mg100k.Value
}
	function updateStats()
		ds:SetAsync(playerKey.."data", data)
		print("Updated")
	end
	
	while true do
		wait(1)
		money.Value = money.Value + 1
	end
	
	money.Changed:Connect(function()
		if money.Value > exp.Value then
			level.Value = level.Value + 1
			exp.Value = exp.Value * 1.2
			print("money is greater than exp")
		end
		
	end)
	
end)


game.Players.PlayerRemoving:Connect(updateStats)```

I see nothing wrong, how do you know it’s not created?

If I test it and look inside the player, there’s only the money instance

money.Value = data.money or 0

How are you saving the data?

It’s a table.
local data = {
money = money.Value;
level = level.Value;
exp = exp.Value;
income = income.Value;
mg1 = mg1.Value;
mg10 = mg10.Value;
mg100 = mg100.Value;
mg1k = mg1k.Value;
mg10k = mg10k.Value;
mg100k = mg100k.Value
}

By the way, I recommend setting the parent property at the end to increase performance.

It’s not recommended to use the parent at the end of the instance.New, as is worsens the performance it has some issues with it linked here

I do believe the issue to be the statement

money.Value = data.money or 0

If data is nil you cannot index it with money or it will error (unless I am incorrect)

instead you can just check if the data is not nil

if data then
  ---update the data
end

I meant after setting all the other properties…

Just tested if this behavior happens and it seems to error (attempt to index nil with money)

local data = nil
local t = data.money or 0 
print(t)

The reason none of them appear after money is because there is an error on the money.Value, as well as the others, just add an if statement, because some people may not have any data and it becomes nil

if it doesn’t work try doing it in a pcall or something