Do you know how to kick out players if they are AFK for 5 minutes

I know there is already a system in ROBLOX which kicks out a player if they are afk for 20 minutes but any idea to change that to 5 minutes? Any help is appreciated! Thanks!

2 Likes

You can use a Idled event which fires every 2 minutes, you can return the time the player has been afk (time is in seconds): Player | Roblox Creator Documentation

game.Players.LocalPlayer.Idled:Connect(function(time)
     if time > 300 then
         game.Players.LocalPlayer:Kick("Afk") 
     end
end)

You can use Player Added to make it work for server scripts also:

game.Players.PlayerAdded:Connect(function(plr)
     plr.Idled:Connect(function(time)
       if time > 300 then
             plr:Kick("Afk") 
       end
     end) 
end)

Excuse me if there’s any errors, I’m currently on mobile :sweat_smile:

5 Likes

I am so sorry for the late reply but where do we put that script? and when I put it in an error comes
Script:1: attempt to index nil with ‘Idled’
and for the second script when I put in workspace the script didnt run
Im probably a noob sorry can you tell how this script works and how to make it work?

2 Likes

Just put the second code he gave as a normal script in ServerScriptService.

Roblox automatically tracks how long a player has been afk. The player.Idled event fires every second that they are afk after they have been afk for two minutes. What this code does is when a player joins the game it waits for the player.idled event to fire, then it checks how many seconds they have been afk for. If they are afk for at least 300 seconds/5 minutes, they get kicked.

1 Like

Put the second code:

In ServerScriptService - image

I apologize for the huge wait my laptop broke down but now im back and I will reply quickly and i tried what you said but it didnt work I went afk for 5 minutes in roblox studio and put the script in serverscript service it didnt work maybe it works on roblox and not roblox studio or it doesnt work for the owner is it anything like that?