In short
Roblox fires Player.Idled about two minutes after a player stops giving input, but only in client scripts. So a LocalScript in StarterPlayerScripts listens for it and fires a RemoteEvent with true, and fires false on the next key press or mouse move. A Script in ServerScriptService checks the value, sets an AFK attribute, moves the character to an AFK zone and calls player:Kick() if they stay AFK too long.
- Idled keeps firing every 30 seconds while the player stays idle, so send the report once, not every time.
- Kick from the server. A LocalScript can only kick its own player, and an exploiter can delete it.
- Roblox disconnects players idle for at least 20 minutes anyway, so set your own limit below that.
Get the script
AFK script: tag, AFK zone and kick
A server Script that marks players AFK when their client reports Player.Idled, shows an AFK tag, moves them to an AFK zone and kicks them after a set time.
-- Script in ServerScriptService named AfkManager.
-- Marks players AFK when their client reports Player.Idled, tags them, moves them and kicks them.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local KICK_AFTER_SECONDS = 600 -- 0 = never kick. Counted from when Idled fires.
local MOVE_TO_AFK_ZONE = true -- needs a part named AfkZone in Workspace
local SHOW_TAG = true
local MIN_SECONDS_BETWEEN = 1 -- ignore reports faster than this
local KICK_MESSAGE = "You were away for too long. Rejoin any time!"
local afkStatus = Instance.new("RemoteEvent")
afkStatus.Name = "AfkStatus"
afkStatus.Parent = ReplicatedStorage
local afkSince: { [Player]: number } = {}
local returnTo: { [Player]: CFrame } = {}
local lastReport: { [Player]: number } = {}
local function setTag(player: Player, on: boolean)
local character = player.Character
local head = character and character:FindFirstChild("Head")
if not head then
return
end
local existing = head:FindFirstChild("AfkTag")
if existing then
existing:Destroy()
end
if not (on and SHOW_TAG) then
return
end
local tag = Instance.new("BillboardGui")
tag.Name = "AfkTag"
tag.Size = UDim2.fromOffset(80, 30)
tag.StudsOffset = Vector3.new(0, 2.5, 0)
tag.AlwaysOnTop = true
local label = Instance.new("TextLabel")
label.Size = UDim2.fromScale(1, 1)
label.BackgroundTransparency = 1
label.Text = "AFK"
label.TextColor3 = Color3.fromRGB(255, 220, 80)
label.TextStrokeTransparency = 0.3
label.Font = Enum.Font.GothamBold
label.TextScaled = true
label.Parent = tag
tag.Parent = head
end
local function setAfk(player: Player, afk: boolean)
if (afkSince[player] ~= nil) == afk then
return -- no change
end
player:SetAttribute("AFK", afk)
setTag(player, afk)
local character = player.Character
local zone = workspace:FindFirstChild("AfkZone")
if afk then
afkSince[player] = os.clock()
if MOVE_TO_AFK_ZONE and character and zone and zone:IsA("BasePart") then
returnTo[player] = character:GetPivot()
character:PivotTo(zone.CFrame + Vector3.new(0, zone.Size.Y / 2 + 3, 0))
end
else
afkSince[player] = nil
local back = returnTo[player]
returnTo[player] = nil
if back and character then
character:PivotTo(back)
end
end
end
afkStatus.OnServerEvent:Connect(function(player: Player, afk: unknown)
if type(afk) ~= "boolean" then
return
end
local now = os.clock()
if now - (lastReport[player] or 0) < MIN_SECONDS_BETWEEN then
return
end
lastReport[player] = now
setAfk(player, afk)
end)
-- A new character starts without the tag; put it back if the player is still AFK
local function onPlayerAdded(player: Player)
player:SetAttribute("AFK", false)
player.CharacterAdded:Connect(function(character: Model)
returnTo[player] = nil
if afkSince[player] then
character:WaitForChild("Head", 5)
setTag(player, true)
end
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in Players:GetPlayers() do
onPlayerAdded(player)
end
Players.PlayerRemoving:Connect(function(player: Player)
afkSince[player] = nil
returnTo[player] = nil
lastReport[player] = nil
end)
-- Kick anyone who has been AFK for too long
while true do
task.wait(10)
if KICK_AFTER_SECONDS > 0 then
local now = os.clock()
for player, since in afkSince do
if now - since >= KICK_AFTER_SECONDS then
afkSince[player] = nil
player:Kick(KICK_MESSAGE)
end
end
end
end
RoCode builds it in the place you have open in Roblox Studio, on Windows or macOS with a desktop browser; on a phone the button sends the prompt and the link to your computer. Free to start, with free credits every day. More Roblox Studio scripts
Where to put it
ReplicatedStorage
AfkStatus RemoteEvent (made by the script)
ServerScriptService
AfkManager Script new
StarterPlayer
StarterPlayerScripts
AfkReporter LocalScript new
Workspace
AfkZone Part (optional)
Settings you can change
KICK_AFTER_SECONDSIn the script- Seconds a player can stay AFK before they are kicked, counted from when Idled fires (about 2 minutes after their last input). Set it to 0 to never kick. Default:
600. MOVE_TO_AFK_ZONEIn the script- Move AFK players to the part named AfkZone, and back to where they were when they return. Default:
true. SHOW_TAGIn the script- Show "AFK" above the head of AFK players. Default:
true.
The LocalScript AfkReporter (Step 2) is what notices the player is idle. Without it the server never hears about AFK players.
What a cheater can and cannot doThe client only sends true or false, which the server type-checks and limits to one change a second. Lying only hurts the liar: claiming to be AFK moves you to the AFK zone, and an exploiter who never reports AFK is still disconnected by Roblox after 20 idle minutes (limits).
Type-checked with luau-lsp strict against Roblox's API definitions on 14 November 2026. Not playtested in Studio yet: press Play and watch the Output window before you publish.
Prompt for RoCode
Add AFK detection to my game: a LocalScript in StarterPlayerScripts that fires an AfkStatus RemoteEvent with true when Player.Idled fires and false on the next input, and a Script in ServerScriptService that checks the value is a boolean with a one second rate limit, sets an AFK attribute, shows AFK over the head, moves the character to a part named AfkZone and back, and kicks players who stay AFK for 10 minutes.
On this page
How AFK detection works in Roblox
Roblox already tracks whether each player is idle, from their keyboard, mouse, touch and controller input. It tells you through the Player.Idled event. The details from Roblox's reference shape the whole design:
| Fact | What it means for your script |
|---|---|
| Fires about 2 minutes after the player becomes idle | A player is "AFK" in your game about 2 minutes after their last input. |
| Keeps firing every 30 seconds while they stay idle | Report once and ignore the repeats. |
| Has no event for coming back | Watch for the next input yourself. |
| Only fires in client scripts | A LocalScript has to tell the server through a RemoteEvent. |
| Roblox disconnects players idle for at least 20 minutes | Your own kick only matters if it is shorter. |
So the work is split. The client notices idleness and activity, because only it can. The server decides what happens: the AFK attribute that other scripts read, the tag, the move and the kick.
Step 1: The server script
- Optional: insert a Part in Workspace named
AfkZone, anchored, somewhere out of the way, such as a small room with walls. AFK players are moved on top of it. - Hover over ServerScriptService, click +, insert a Script named
AfkManagerand paste the code below.
-- Script in ServerScriptService named AfkManager.
-- Marks players AFK when their client reports Player.Idled, tags them, moves them and kicks them.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local KICK_AFTER_SECONDS = 600 -- 0 = never kick. Counted from when Idled fires.
local MOVE_TO_AFK_ZONE = true -- needs a part named AfkZone in Workspace
local SHOW_TAG = true
local MIN_SECONDS_BETWEEN = 1 -- ignore reports faster than this
local KICK_MESSAGE = "You were away for too long. Rejoin any time!"
local afkStatus = Instance.new("RemoteEvent")
afkStatus.Name = "AfkStatus"
afkStatus.Parent = ReplicatedStorage
local afkSince: { [Player]: number } = {}
local returnTo: { [Player]: CFrame } = {}
local lastReport: { [Player]: number } = {}
local function setTag(player: Player, on: boolean)
local character = player.Character
local head = character and character:FindFirstChild("Head")
if not head then
return
end
local existing = head:FindFirstChild("AfkTag")
if existing then
existing:Destroy()
end
if not (on and SHOW_TAG) then
return
end
local tag = Instance.new("BillboardGui")
tag.Name = "AfkTag"
tag.Size = UDim2.fromOffset(80, 30)
tag.StudsOffset = Vector3.new(0, 2.5, 0)
tag.AlwaysOnTop = true
local label = Instance.new("TextLabel")
label.Size = UDim2.fromScale(1, 1)
label.BackgroundTransparency = 1
label.Text = "AFK"
label.TextColor3 = Color3.fromRGB(255, 220, 80)
label.TextStrokeTransparency = 0.3
label.Font = Enum.Font.GothamBold
label.TextScaled = true
label.Parent = tag
tag.Parent = head
end
local function setAfk(player: Player, afk: boolean)
if (afkSince[player] ~= nil) == afk then
return -- no change
end
player:SetAttribute("AFK", afk)
setTag(player, afk)
local character = player.Character
local zone = workspace:FindFirstChild("AfkZone")
if afk then
afkSince[player] = os.clock()
if MOVE_TO_AFK_ZONE and character and zone and zone:IsA("BasePart") then
returnTo[player] = character:GetPivot()
character:PivotTo(zone.CFrame + Vector3.new(0, zone.Size.Y / 2 + 3, 0))
end
else
afkSince[player] = nil
local back = returnTo[player]
returnTo[player] = nil
if back and character then
character:PivotTo(back)
end
end
end
afkStatus.OnServerEvent:Connect(function(player: Player, afk: unknown)
if type(afk) ~= "boolean" then
return
end
local now = os.clock()
if now - (lastReport[player] or 0) < MIN_SECONDS_BETWEEN then
return
end
lastReport[player] = now
setAfk(player, afk)
end)
-- A new character starts without the tag; put it back if the player is still AFK
local function onPlayerAdded(player: Player)
player:SetAttribute("AFK", false)
player.CharacterAdded:Connect(function(character: Model)
returnTo[player] = nil
if afkSince[player] then
character:WaitForChild("Head", 5)
setTag(player, true)
end
end)
end
Players.PlayerAdded:Connect(onPlayerAdded)
for _, player in Players:GetPlayers() do
onPlayerAdded(player)
end
Players.PlayerRemoving:Connect(function(player: Player)
afkSince[player] = nil
returnTo[player] = nil
lastReport[player] = nil
end)
-- Kick anyone who has been AFK for too long
while true do
task.wait(10)
if KICK_AFTER_SECONDS > 0 then
local now = os.clock()
for player, since in afkSince do
if now - since >= KICK_AFTER_SECONDS then
afkSince[player] = nil
player:Kick(KICK_MESSAGE)
end
end
end
end
What each part does
- The RemoteEvent handler only accepts a boolean and only one change a second per player. Anything else is ignored.
- setAfk does nothing if the state did not change, then sets the
AFKattribute, adds or removes the tag, and moves the character withPivotTo. The spot the player left from is saved inreturnTo, so they come back to it. - The kick loop runs every 10 seconds and kicks anyone AFK for at least
KICK_AFTER_SECONDS. With the default 600, a player is kicked about 12 minutes after their last input: 2 minutes until Idled fires, then 10 more. - Respawns clear the saved spot (the old body is gone) and put the tag back on the new head.
Keep KICK_MESSAGE short. Roblox's Player reference says a kick message from the server longer than 500 bytes is dropped and the player sees the default message instead.
Step 2: The client reporter
- In the Explorer, open StarterPlayer, hover over StarterPlayerScripts, click + and insert a LocalScript named
AfkReporter. - Paste the code below.
-- LocalScript in StarterPlayerScripts named AfkReporter.
-- Tells the server when this player goes idle (Player.Idled) and when they come back.
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local afkStatus = ReplicatedStorage:WaitForChild("AfkStatus") :: RemoteEvent
local reportedIdle = false
-- Fires about 2 minutes after the player stops giving input, then every 30 seconds
player.Idled:Connect(function(_idleSeconds: number)
if not reportedIdle then
reportedIdle = true
afkStatus:FireServer(true)
end
end)
-- Idled has no "came back" event, so the next input counts as coming back
local function onInput(input: InputObject)
if not reportedIdle then
return
end
local kind = input.UserInputType
if kind == Enum.UserInputType.Keyboard
or kind == Enum.UserInputType.MouseButton1
or kind == Enum.UserInputType.MouseButton2
or kind == Enum.UserInputType.MouseMovement
or kind == Enum.UserInputType.Touch
or kind == Enum.UserInputType.Gamepad1
then
reportedIdle = false
afkStatus:FireServer(false)
end
end
UserInputService.InputBegan:Connect(onInput)
UserInputService.InputChanged:Connect(onInput)
The script sends true once when Idled first fires and ignores the repeats every 30 seconds. On the next key, click, mouse move, touch or controller input it sends false. Mouse movement comes through InputChanged, not InputBegan, which is why both are connected.
It lives in StarterPlayerScripts rather than StarterCharacterScripts so it keeps running when the character respawns, and so reportedIdle is not reset by a death.
Step 3: Use the AFK attribute in other scripts
Other server scripts can read player:GetAttribute("AFK"). Two common uses:
- Round games: skip AFK players when choosing who goes into the next round, so a round does not start with someone who will not move. In the round system guide, filter the player list with
if player:GetAttribute("AFK") ~= true then. - Rewards over time: if you pay coins every minute for being in the game, stop paying AFK players, or pay them on purpose if your game has an AFK reward zone.
-- Example: only players who are not AFK join the round
local Players = game:GetService("Players")
local function activePlayers(): { Player }
local list = {}
for _, player in Players:GetPlayers() do
if player:GetAttribute("AFK") ~= true then
table.insert(list, player)
end
end
return list
end
print(#activePlayers() .. " players are active")
Read the attribute on the server for anything that matters. An exploiter can change attributes on their own copy of the Player, but the change never reaches the server.
What this can and cannot catch
AFK detection is a convenience for honest players, not anti-cheat. Be clear about what it covers:
| Player | What happens |
|---|---|
| Walked away from the keyboard | Marked AFK after about 2 minutes, moved, kicked after your limit. |
| Left the game open in another window | Roblox decides from their input, so they are marked AFK the same way. |
| Uses an auto-clicker or a key repeater | That is input, so Roblox does not count them as idle. This script cannot tell. |
| An exploiter who blocks the report | Never marked AFK by you. Roblox still disconnects them after 20 idle minutes. |
If your game pays for time online, an auto-clicker beats any AFK check. Pay for things the server can see the player do instead, such as finishing a round or collecting a coin. The anti-exploit guide covers what server checks can and cannot do.
Step 4: Test it
- Set
KICK_AFTER_SECONDSto 30 while testing. - Press Play, then take your hands off the keyboard and mouse. Idled fires after about 2 minutes: you are moved to the AfkZone and "AFK" appears over your head.
- Move the mouse. You go back to where you were and the tag disappears.
- Go idle again and wait the 30 seconds plus up to 10 for the loop. You are kicked with the message.
- If nothing happens after 3 or 4 minutes, check the Output window for errors and that AfkReporter is a LocalScript in StarterPlayerScripts. If it still never fires in Studio, test in a published server.
- Set
KICK_AFTER_SECONDSback before you publish.
Common errors and fixes
Check the Output window first, both the client and the server view.
Player.Idled never fires
It only fires in client scripts, so a Script in ServerScriptService connected to it never runs. Use the LocalScript from Step 2. It also takes about 2 minutes of no input, and moving the mouse at all resets it.
Cannot kick a non-local player from a LocalScript
A LocalScript can only kick its own player. Kick from the server, as AfkManager does. See that error's page.
Players are not moved to the AFK zone
The part must be named exactly AfkZone and sit directly in Workspace, and MOVE_TO_AFK_ZONE must be true.
Infinite yield possible on WaitForChild("AfkStatus")
AfkManager makes the RemoteEvent. If it is disabled or errors before that line, the LocalScript waits forever. See Infinite yield possible.
Build it with RoCode
If you would rather not set it up by hand, RoCode can add AFK handling to the place you have open. RoCode is an independent AI agent for Roblox Studio, not made by Roblox: you describe the change in a web chat, and its Studio plugin creates the scripts in your Explorer.
Add AFK detection to my game: show AFK over idle players, move them to an AFK room, keep them out of the next round, and kick them after 10 minutes.
- Can read your place first to find your round script and where an AFK room would fit
- Writes the scripts with Create Script and is told to compile-check each one with Check Script
- Sets an undo point before and after each batch of changes, so Ctrl+Z steps back one batch at a time
Questions
How do I detect if a player is AFK in Roblox?
Connect to Player.Idled in a LocalScript. It fires about two minutes after the player stops giving input. Send that to the server with a RemoteEvent, as in Step 2.
How do I kick AFK players in Roblox?
Have the server track when each player went AFK and call player:Kick("message") once they have been AFK too long. Step 1 does this every 10 seconds.
Does Roblox kick AFK players automatically?
Yes. Roblox's reference says it disconnects players who have been idle for at least 20 minutes. Your own kick only matters if it is shorter.
Can I use Player.Idled in a server script?
No. It only fires in client scripts. Listen in a LocalScript and tell the server with a RemoteEvent.
How do I make an AFK zone in Roblox?
Make a part named AfkZone and move idle players onto it with character:PivotTo() on the server, saving where they were so you can move them back. The AfkManager script does both.
Sources and further reading
- Roblox Creator Docs: Player.Idled. the 2 minute and 30 second timings, client only, the 20 minute disconnect
- Roblox Creator Docs: Player:Kick. kicking from the server and the message limit
- Roblox Creator Docs: UserInputService. InputBegan and InputChanged
- Roblox Creator Docs: Remote events and callbacks. sending the report to the server
How the code was checked: every script on this page passes Luau's strict type checker against Roblox's API definitions (luau-lsp, 14 November 2026). A type check catches misspelt APIs and wrong types, not game logic, so playtest in Studio before you publish.