Logging time in-game

I’m trying to create an activity system. Basically, I want to create a system that starts when a player joins the game and ends when a player leaves. How would I go about doing that?

Use a Webhook, or link it to any page.

Also read this, may help: How do you create a timer that counts a players time? - #3 by MJTFreeTime

local Players = game:GetService("Players")
local Timers = {}

Players.PlayerAdded:Connect(function(Player)
    Timers[Player.UserId] = {
        Start = os.time()
    }
end)

Players.PlayerRemoving:Connect(function(Player)
    Timers[Player.UserId].End = os.time()

    local TotalTime = Timers[Player.UserId].End - Timers[Player.UserId].Start
    print(Player.Name, "was here for", TotalTime, "seconds.")
end)

So basically you’re creating a table which will store the time the player started playing when they join the game. When they leave, you’ll store the time they left. You can subtract the start time from the end time to figure out how many seconds they played for.

We’re using their UserId as the key, as you can still access this after they’ve left to find out who they were.

3 Likes

Can‘t they just change the os time, and they can bypass this?

This would be running in a server script, therefore os.time() would be based on the server clock.

2 Likes

Would I be able to actually use this with Trello? I would create a card for that user in a certain list titled “UserId | Time" and then when they leave, it would change the ‘Time’ section to be the amount of time they were in-game?

You certainly can. You’ll have to find the card containing their UserId in order to update the card and move it back to the top of the list, rather than creating a new card for each session.

I believe the API returns the card ID when creating a new card, so you can easily update the card during/at the end of the session.

Okay, thank you so much! I’m going to use the Trello API to find the card with that UserId and modify the time section with their new time.

1 Like