AFK Timer
Key RequiredUniversal

AFK Timer

Universal ScriptUnsightedManUnsightedMan 2.4K views 49 executesUpdated Nov 8, 2025
5.0/ 5(2 votes)
20100% Positive
Lua Script•83 lines (2713 chars)
-- // 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)

Features & Information

(Actually, the server doesn't keep track of how long you're AFK; that's done by your own engine, but it doesn't start immediately after you go AFK, it starts 2 minutes later, which is why there are different counters) I want to clarify that I used chatgpt, but it didn't do everything. I created the script and then asked it to use the interface and take care of all the "pretty" stuff.
#Universal#ChatGPT

Community Comments (2)

LamiiaLamiiaNov 8, 2025

first time knowing this mechanic

Replying to @Lamiia
UnsightedManUnsightedManNov 8, 2025

@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.

More Scripts for Universal Scripts