I’ve been thinking of ways to award more badges for my players. I happened to come across “You came back the next day”, “You played for 1 week”, etc badges. I’m wondering how they program these? Do they use datastores to store when the user last played?
1 Like
Yes. Using os.time()
thirty character limit
How would I achieve programming this as I cannot script time as I’ve never really needed to use it
Just save the time of them logging on and check it, when they come back.
Don’t they just save the sessionTime, which is a number, added with the totalSessionTime?
When a player joins, track their time using a timer based on tick() or os.time().
local tracker = {}
game:GetService("Players").PlayerAdded:Connect(function(player)
tracker[player.UserId] = tick()
end)
game:GetService("Players").PlayerRemoving:Connect(function(player)
local last = tick()
if tracker[player.UserId] then
print(last - tracker[player.UserId]) -- prints total time played in one session
end
end
You will have to calculate the time to match a week. However, the only backlash in the example above is clearly the badge giving in time. You will have to run a loop with a long interval to check the player’s total time.