UserInputService Focus not working?

Here’s a pretty simple snippet:

game:GetService("UserInputService").InputEnded:connect(function(ib)
	if ib.UserInputType == Enum.UserInputType.Focus then
		print("Roblox client has lost focus")
	end
end)
game:GetService("UserInputService").InputBegan:connect(function(ib)
	if ib.UserInputType == Enum.UserInputType.Focus then
		print("Roblox client has regained focus")
	end
end)
game:GetService("UserInputService").InputChanged:connect(function(ib)
	if ib.UserInputType == Enum.UserInputType.Focus then
		print("Roblox client has changed focus")
	end
end)

The problem is, it prints nothing in online mode. It does work in studio.

Why would you need to know if the window is in focus or not? Here are some examples:

  • Run things at lower frequency when focus is lost to conserve power (much like roblox studio).
  • Stop actions when focus is lost. (clicking on the taskbar to switch tasks, pressing Alt and Tab, gamepad input)
  • Automatically pause the game when focus is lost.

This place is a repro of the bug.

Have you tried these events?
UserInputService.WindowFocused
UserInputService.WindowFocusReleased
Using Enum.UserInputType.Focus works for me in studio but not online.

I just tried what you suggested, and it doesn’t seem to work:

game:GetService("UserInputService").WindowFocused:connect(function()
	print("window focused")
end)
game:GetService("UserInputService").WindowFocusReleased:connect(function()
	print("window unfocused")
end)

The above code also prints nothing in online mode.

Could this be related to mouse clicks registering when you click off of the ROBLOX window?

I will look into this, thanks. I assume you are trying on a pc?

That is correct. Thanks!