local PlayerStatManager = {}
local DataStoreService = game:GetService("DataStoreService")
local playerData = DataStoreService:GetDataStore("PlayerData")
local sessionData = {game.Players.LocalPlayer.leaderstats.Cash.Value,
game.Players.leaderstats.Subscribrers.Value}
local AUTOSAVE_INTERVAL = 120
function PlayerStatManager:ChangeStat(player, statName, value)
local playerUserId = "Player_"..player.UserId
assert(typeof(sessionData[playerUserId][statName]) == typeof(value), "ChangeStat error: types do not match")
if typeof(sessionData[playerUserId][statName]) == "number" then
sessionData[playerUserId][statName] = sessionData[playerUserId][statName] + value
else
sessionData[playerUserId][statName] = value
end
end
local function setupPlayerData(player)
local playerUserId = "Player_"..player.UserId
local data = playerData:GetAsync(playerUserId)
if data then
sessionData[playerUserId] = data
else
sessionData[playerUserId] = {Cash=0, Subscribers=0}
end
end
local function savePlayerData(playerUserId)
if sessionData[playerUserId] then
playerData:SetAsync(playerUserId, sessionData[playerUserId])
end
end
local function saveOnExit(player)
local playerUserId = "Player_"..player.UserId
savePlayerData(playerUserId)
end
local function autoSave()
while wait(AUTOSAVE_INTERVAL) do
for playerUserId, data in pairs(sessionData) do
savePlayerData(playerUserId)
end
end
end
spawn(autoSave)
game.Players.PlayerAdded:Connect(setupPlayerData)
return PlayerStatManager
Data is not saving. I followed the ROBLOX WIKI.

7 comments
try using my blog
its in the forums xd
neil wat
I'd rather do it this way, so I can learn where I went wrong. Anyone know what is wrong?
Make sure this is in a Script (not localscript) in ServerScriptService
Are you gettting any error messages?
It's a module script inside server storage where they said to put it..