Profile Service is not working

I made leaderstats using ProfileService, but when I leave from the game, they stats dont save. There are no errors, and the API is enabled. Does anyone know what to do?

DataManager :

local Players = game:GetService("Players")
local SSS = game:GetService("ServerScriptService")
local Modules = SSS:WaitForChild("ProfileService")

local ProfileService = require(Modules:WaitForChild("ProfileService"))
local template = require(script:WaitForChild("Template"))
local leaderstats = require(script:WaitForChild("Leaderstats"))

local DataKey = "_TestDataStore21"
local ProfileStore = ProfileService.GetProfileStore(DataKey, template)

local DataManager = {}
DataManager.profiles = {}

local function PlayerAdded(plr : Player)
	local profile = ProfileStore:LoadProfileAsync("Player_"..plr.UserId)
	
	if profile ~= nil then
		profile:AddUserId(plr.UserId)
		profile:Reconcile()
		
		profile:ListenToRelease(function()
			DataManager.profiles[plr] = nil
			plr:Kick()
		end)

		if plr:IsDescendantOf(Players) then
			DataManager.profiles[plr] = profile
			leaderstats:Create(plr, profile)
		else
			profile.Release()
		end
	else
		plr:Kick()
	end
end

local function PlayerRemoving(plr: Player)
	local profile = DataManager.profiles[plr]
	if profile ~= nil then
		print("Saved")
		profile:Release()
	end
end
for _, plr in Players:GetPlayers() do
	task.spawn(PlayerAdded, plr)
end

Players.PlayerAdded:Connect(PlayerAdded)
Players.PlayerRemoving:Connect(PlayerRemoving)

return DataManager

Tamplate:

local template = {
	Cash = 0,
}

return template

Leaderstats:

local leaderstats = {}

function leaderstats:Create(plr : Player, profile)
	local leaderstats = Instance.new("Folder")
	leaderstats.Parent = plr
	leaderstats.Name = "leaderstats"
	
	local Cash = Instance.new("IntValue")
	Cash.Parent = leaderstats
	Cash.Name = "Cash"
	Cash.Value = profile.Data.Cash
	
	local Data = Instance.new("Folder")
	Data.Parent = plr
	Data.Name = "Data"
	
	local DoubleSpin = Instance.new("BoolValue")
	DoubleSpin.Parent = Data
	DoubleSpin.Name = "DoubleSpin"
	DoubleSpin.Value = false
	
end


return leaderstats

The main issue I see here is that you’re not writing to profile.Data whenever the Cash changes.

Try connecting to Cash.Changed and assign the profile.Data.Cash to the new value!

Also at a quick glance I noticed

Release is always a method so make sure you’re using profile:Release()