local PlayerStatManager = {}
local sessionData = {}
local AUTOSAVE_INTERVAL = 60 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 sessionData[playerUserId] = {Money=0, Experience=0} end
game.Players.PlayerAdded:Connect(setupPlayerData)
return PlayerStatManager
local datastore = game:GetService("DataStoreService") local datastore1 = DataStoreService:GetDataStore("Time Save System")
game.Players.PlayerAdded:connect(function(player) local folder = Instance.new("Folder", player) folder.Name = "leaderstats" local Time = Instance.new("IntValue", folder) local Stats = Instance.new("Model", player) Stats.Name = "leaderstats" local Timer = Instance.new("IntValue", Stats) Timer.Name = "Time(s)" local datastore1 = datastore:GetDataStore(Timer.Value) local success, err = pcall(function() datastore1:UpdateAsync(player.UserId, Timer.Value) end) Timer.Value = datastore1:GetAsync(player.UserId) or 0 Timer.Changed:connect(function() Timer.Value = datastore1 while true do wait(1) Timer.Value = Timer.Value + 1 end end)
end)

1 comment
any help is appreciated Just started out with lua