Session Logger Plugin

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

:SetSetting("something_" .. tostring(game.PlaceId), v)?

1 Like

please read carefully

I can’t do what you suggested, but thanks for your effort

What do you mean exactly? SetSetting is local.

1 Like

SetSetting has nothing to do with the internet. It updates a JSON plugin settings file on your hard drive …?

1 Like

PlaceId is 0 for offline places, I’m aware that SetSetting is local

if I did what you suggested then I can’t save data for each individual offline place because it’s offline

You can create an object to act as a UUID under the datamodel. Create this instance only once, and read from it after.

1 Like

This is still how you’d do it. You just need another way to identify the place.
E.g. GUID saved somewhere in the datamodel.

You should be more careful about how you word help requests. “Offline” doesn’t make any sense in this context, especially not since you said you already considered and discarded two services that are very “Online”. This sets the context for your use of this word to the Internet, and not to what you actually meant.

2 Likes