
KeylessUniversal

-- // Libraries
local Library = loadstring(game:HttpGet("https://raw.githubusercontent.com/xHeptc/Kavo-UI-Library/main/source.lua"))()
local Window = Library.CreateLib("AFK Time", "DarkTheme")
local Tab = Window:NewTab("AFK")
local AFKsection = Tab:NewSection("AFK Timers")
-- // UI Labels
local clientAFKLabel = AFKsection:NewLabel("AFK (Client): 00:00")
local serverAFKLabel = AFKsection:NewLabel("AFK (Server): 00:00")
local serverStatusLabel = AFKsection:NewLabel("AFK by Server: False")
-- // Services
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
-- // Time Variables
local lastActive = tick() -- last time the player did something
local clientAFKTime = 0 -- client AFK time
local serverAFKTime = 0 -- server/motor AFK time
local serverAFKStart = nil -- moment server considers player AFK
local isAFKByServer = false
-- // Function to format seconds to MM:SS
local function formatTime(seconds)
local minutes = math.floor(seconds / 60)
local secs = math.floor(seconds % 60)
return string.format("%02d:%02d", minutes, secs)
end
----------------------------------------------------------
-- 🕒 Detect player activity (client-side)
----------------------------------------------------------
UserInputService.InputBegan:Connect(function()
lastActive = tick()
if isAFKByServer then
isAFKByServer = false
serverAFKStart = nil
serverAFKTime = 0
serverStatusLabel:UpdateLabel("AFK by Server: False")
end
end)
UserInputService.InputChanged:Connect(function()
lastActive = tick()
if isAFKByServer then
isAFKByServer = false
serverAFKStart = nil
serverAFKTime = 0
serverStatusLabel:UpdateLabel("AFK by Server: False")
end
end)
----------------------------------------------------------
-- ⚙️ Server/motor AFK detection
----------------------------------------------------------
player.Idled:Connect(function(time)
isAFKByServer = true
serverAFKStart = tick() - time
serverStatusLabel:UpdateLabel("AFK by Server: True")
-- Loop to update server AFK timer in real time
task.spawn(function()
while isAFKByServer do
serverAFKTime = tick() - serverAFKStart
serverAFKLabel:UpdateLabel("AFK (Server): " .. formatTime(serverAFKTime))
task.wait(0.2)
end
serverAFKLabel:UpdateLabel("AFK (Server): 00:00")
end)
end)
----------------------------------------------------------
-- 🔁 Client AFK timer update loop
----------------------------------------------------------
task.spawn(function()
while true do
clientAFKTime = tick() - lastActive
clientAFKLabel:UpdateLabel("AFK (Client): " .. formatTime(clientAFKTime))
task.wait(0.2)
end
end)
![[KEYLESS] Moondiety Script | 17+ supported Games](https://scriptblox.com/images/sb/0-1753093706828.png)


first time knowing this mechanic
@Lamiia Me too, I was on the Roblox Studio forum and I realized that when the engine considers you AFK it starts a counter that can be obtained as an argument of the event, so I found it interesting.