I’m trying to create a plugin that logs session time in Studio but I don’t know how to make it save values upon exit without using HTTPService and DataStoreService. (this is for using offline)
I read a lot of documents for Plugins and I didn’t find anything that would help with saving local data
Code
--| SERVICES:
local HttpS = game:GetService("HttpService")
--| VARIABLES:
local startTime = os.time()
local createdTime = game:FindFirstChild("createdTime",true)
local sessionsData;
--
--| SCRIPTS:
if (not createdTime) then
createdTime = Instance.new("NumberValue")
createdTime.Name = "createdTime"
createdTime.Value = os.time()
local sessionsData = Instance.new("StringValue")
sessionsData.Name = "sessionsData"
sessionsData.Value = HttpS:JSONEncode({})
sessionsData.Parent = createdTime
createdTime.Parent = game.TestService
end
sessionsData = HttpS:JSONDecode(createdTime.sessionsData.Value)
local totalSessionsTime
for _,v in ipairs(sessionsData) do
totalSessionsTime = totalSessionsTime + v.sessionTime
end
if #sessionsData > 0 then
print("Recent Session:",sessionsData[#sessionsData].Date)
print("Total Sessions:",#sessionsData)
print("Total Sessions Time:",#totalSessionsTime)
end
game:BindToClose(function()
local osTime = os.time()
table.insert(sessionsData,{
Date = os.date(),
sessionTime = osTime - startTime,
startTime = startTime,
endTime = osTime,
})
createdTime.sessionsData.Value = HttpS:JSONEncode(sessionsData)
end)
edit
I found these
let me know if you have a better way, because this isn’t ideal for my session logger, I want to log data for each place separately