Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Services
- local replicatedStorage = game:GetService("ReplicatedStorage")
- local serverStorage = game:GetService("ServerStorage")
- local dataStoreService = game:GetService("DataStoreService")
- local players = game:GetService("Players")
- -- Datastores
- local analyticsStore = dataStoreService:GetDataStore("GameAnalytics")
- -- Server
- local classes = serverStorage:WaitForChild("Classes")
- local configurations = serverStorage:WaitForChild("Configurations")
- local singletons = serverStorage:WaitForChild("Singletons")
- -- Configurations
- local getGeneralAnalytics = require(configurations:WaitForChild("GeneralAnalytics"))
- local playerAnalytics = require(configurations:WaitForChild("PlayerAnalytics"))
- -- Server modules
- local DSInterface = require(classes:WaitForChild("DSInterface"))
- -- Singletons
- local analyticsManager = require(singletons:WaitForChild("AnalyticsManager"))
- -- Modules
- local dataStore = require(classes.DataStore2)
- -- Constants
- local START_YEAR = 2021
- local KEY_STR = "DATE _ %s - %s"
- -- Function cache
- local osTime = os.time
- local osDate = os.date
- local stringLower = string.lower
- local stringFormat = string.format
- local mathRandom = math.random
- -- Tables
- local generalAnalytics = {
- ActiveUsers = {
- Day = 0,
- Month = 0
- },
- TotalUsers = 0
- }
- -- Functions
- local function subGet(array, index)
- return array[index] - 1
- end
- -- Post-function variables
- local generalAnalytics = getGeneralAnalytics()
- local function saveAnalytics()
- analyticsManager:IncrementAnalytics(generalAnalytics)
- generalAnalytics = getGeneralAnalytics()
- end
- -- Event connections
- players.PlayerAdded:Connect(function(plr)
- local analyticsOBJ = dataStore("Analytics", plr)
- local getValue = analyticsOBJ:Get()
- local analytics = getValue or playerAnalytics()
- local currentTime = osTime()
- local currentDate = osDate("*t")
- currentDate.year -= START_YEAR
- local lastJoined = analytics.LastJoined
- local activeUsers = generalAnalytics.ActiveUsers
- local isDifferent
- for timePeriod, value in pairs(lastJoined) do
- -- timePeriod is "Day"
- -- value is 0
- local currentValue = currentDate[stringLower(timePeriod)] -- currentDate["day"] ( 1 )
- if isDifferent or (currentValue ~= value) then -- True, value is not the same as currentValue
- print(timePeriod, value)
- print(currentValue)
- activeUsers[timePeriod] += 1
- lastJoined[timePeriod] = currentValue -- lastJoined.Day = 1
- isDifferent = true
- end
- local firstStr = "Currently, the %s is: %s"
- local secondStr = "The player last joined on the %s"
- end
- if not analytics.HasJoined then
- generalAnalytics.UniqueUsers += 1
- analytics.HasJoined = true
- end
- analyticsOBJ:Set(analytics)
- end)
- coroutine.wrap(function()
- while true do
- wait(12)
- saveAnalytics()
- wait(530 + mathRandom(1, 100))
- end
- end)()
Advertisement
Add Comment
Please, Sign In to add comment