-- For this to save you must go to Game Settings, Security, and enable Acess to API Services --


local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("TimeStats")

game.Players.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder")
    Leaderstats.Name = "leaderstats"
    Leaderstats.Parent = Player
    local Cash = Instance.new("IntValue")
    Cash.Name = "Cash"
    Cash.Value = 0
    Cash.Parent = Leaderstats
    
    local Data = DataStore:GetAsync(Player.UserId)
    if Data then
        Cash.Value = Data
    end
    
    
    end)


game.Players.PlayerRemoving:Connect(function(Player)
    DataStore:SetAsync(Player.UserId, Player.leaderstats.Cash.Value)
end)
