How to detect if a player "tabs out" of your game/Roblox player client?

I really want to know if there is specifically a way to detect if a player is viewing some other tab than your game. At first I really do not think this is possible, but is there any exact way to do that?

6 Likes

I assume that the thing you are trying to achieve is to check if the player is afk or not. If thats the case you can allways use the UserInputService to check if they began an input in a certain amount of time.

14 Likes

Hey there, I have been trying to use these two but both of them seem broken, is it a bug? Could you please confirm this?

I know this topic is old but here is some code that works inside a local script:

local UserInputService = game:GetService("UserInputService")

UserInputService.WindowFocused:Connect(function()
	print("Focus Gained!")
end)

UserInputService.WindowFocusReleased:Connect(function()
	print("Focus Realeased!")
end)
13 Likes