Why won't just 2 stats save?

Hello, fellow developers. Today I set up a cash, level, and exp system, following a HowToRoblox tutorial for the level and exp stats. While playtesting, I found that only the cash leaderstat saves, and not the other ones. I’ve looked through the script and found nothing that could be causing this problem. It isn’t any external scripts either, as the only ones that use them work perfectly fine with the cash as well. Any help?

The tutorial video: How to Make a LEVEL SYSTEM | HowToRoblox

The Leaderstats script (inside ServerScriptService):

local DataStoreService = game:GetService("DataStoreService")
local CashDataStore = DataStoreService:GetDataStore("Cash")
local LevelDataStore = DataStoreService:GetDataStore("Level")
local ExpDataStore = DataStoreService:GetDataStore("Exp")

function incrementExp(player, increment)

	for i = player.leaderstats.Exp.Value, player.leaderstats.Exp.Value + increment do

		player.leaderstats.Exp.Value = i

		wait()
	end
end

game.Players.PlayerAdded:Connect(function(Player)
	local Leaderstats = Instance.new("Folder", Player)
	Leaderstats.Name = "leaderstats"

	local Cash = Instance.new("IntValue", Leaderstats)
	Cash.Name = "Cash" 
	Cash.Value = 0
	
	local Level = Instance.new("IntValue", Leaderstats)
	Level.Name = "Level"
	Level.Value = 1

	local Exp = Instance.new("IntValue", Leaderstats)
	Exp.Name = "Exp"
	Exp.Value = 0

	local CashData = CashDataStore:GetAsync(Player.UserId)
	if CashData then
		Cash.Value = CashData.Cash
	end
	
	local LevelData = LevelDataStore:GetAsync(Player.UserId)
	if LevelData then
		Level.Value = LevelData.Cash
	end
	
	local ExpData = ExpDataStore:GetAsync(Player.UserId)
	if ExpData then
		Exp.Value = ExpData.Cash
	end
	
	Exp:GetPropertyChangedSignal("Value"):Connect(function()
		local neededExp = math.floor(Level.Value ^ 1.5 + 0.5) * 500

		if Exp.Value >= neededExp then
			Level.Value += 1
		end
	end)
end)


game.Players.PlayerRemoving:Connect(function(Player)
	CashDataStore:SetAsync(Player.UserId, {
		["Cash"] = Player.leaderstats.Cash.Value;
	})
	
	LevelDataStore:SetAsync(Player.UserId, {
		["Level"] = Player.leaderstats.Level.Value;
	})
	
	ExpDataStore:SetAsync(Player.UserId, {
		["Exp"] = Player.leaderstats.Exp.Value;
	})
end)

Thanks,
SpeakerDev

No errors in the script at all? Is this a local script or a server script?

It throws no errors. Everything works perfectly: I can gain exp and once I reach a certain level of exp you gain a level. It just doesn’t save, but it’s especially weird because the cash stat saves, just not the others. It is a server script located inside ServerScriptService.

Are you sure it’s not because you did

Level.Value = LevelData.Cash
Exp.Value = ExpData.Cash

Should they be checking .Cash as well?

1 Like

I highly recommend this module for saving data, I use it and love it.

Here’s a tutorial if you want to learn it.

I’m sorry, but I’m not looking to add a module to my game. My saving works perfectly fine with the cash, which is why I believe the problem lies around something else. Thank you for helping.

Thank you my kind sir. Not only does it save but now I know that I am blind.