How would I detect if a player is AFK?

I’ve tried using the Idled event, but it doesn’t ever fire. Maybe I’m doing something wrong. Here is the script:

game:GetService("Players").PlayerAdded:Connect(function(player)
	player.Idled:Connect(function()
		print("Player is AFK!")
	end)
end)

I couldn’t find other solutions here other than the Idled event. I tried using UserInputService, but I’m afraid it would eat up too many resources. The final script that includes AFK detection is for a nametag above the player that says, “AFK!”. Thank you!

4 Likes

First, the Idled event does not fire. As far as I know, this has been the case for the past few years and hasn’t been fixed. If you really want to know if a player is idle, just use UserInputService. It won’t take a lot of resources. Example:

local function inputChanged(input)
    idle = tick()
    
    local now = idle
    
    wait(120) --2 minutes
    
    if idle == now then --Check if idle is still equal to now. If so, the player is AFK.
        --The player is AFK
    end
end
4 Likes

You could just do something like this:

local idle = false
local timer  = 0
UIS.InputEnded:Connect(function()
      idle = true
      while wait(1) do
            timer += 1
            if not idle then
               break
            end
            if timer >= 180 then
               localPlayer:Kick("Been afk for 3 minutes")
               break
            end
      end
end)
UIS.InputBegan:Connect(function()
      idle = false
end)
17 Likes

Thank you! This method works very well!

1 Like

Thank you for informing me! I didn’t know that the Idled event is broken. Unfortunately, your method didn’t work for me.

1 Like

supposing this is old news, but the idled event works in the client, at least for now. it seems to first trigger between 2 and 3 minutes, then every 30 secs afterwards. the callback argument has the total idle time (secs).

1 Like