Kick Player after Certain Time AFK

I’m attempting to create a system that detects if a player is AFK for more than 5 minutes, but everything I’ve tried so far hasn’t worked out very well.

I attempted to use WindowFocusReleased and WindowFocused, and then check every 300 seconds or so if they are AFK or not from a variable that was set to true or false every time WindowFocusReleased and WindowFocused were fired.

The only problem with that was that say they were not AFK for 280 seconds, and then was AFK for the remaining 20. The variable would be set to true, as they were AFK, and the script would kick them even though they had only been AFK for 20 seconds.

If anyone could point me in the right direction, it would be greatly appreciated.

1 Like

This might help:

You could use this to reset the timer every-time they move.

1 Like

It fires when a player is idle for 2 minutes, but from there it will fire every second. Use this instead. A player isn’t not AFK simply based on the focused state of the window - they can leave the Roblox window open but not be at their keyboard.

5 Likes

Ah. I hadn’t seen that before. Thanks.

1 Like