Can you check if a player is tabbed in or out with the server?

I’m trying to make an afk system but it has a remote, which can easily just be used by exploiters to go afk so in my server script I want to have something that checks whether their window is focused to actually check if they are afk, is there a way of doing this?

I dont think so. The window is on the client.

2 Likes

I am not sure that there is a way to do this, as ryanadamdragon said above me, the window is on the client.

You could possibly check if the player is AFK on the server if they are not moving for a certain time. That might be the only not easily exploitable way to do this.

What’s your exact use case for needing to determine this from the server? Setting an AFK status should be client authoritative regardless. Why is it a problem if exploiters tell the server that they are AFK when they actually aren’t?

1 Like

create a global variable and just use the event WindowFoucsed

https://developer.roblox.com/en-us/api-reference/event/UserInputService/WindowFocused
https://developer.roblox.com/en-us/api-reference/event/UserInputService/WindowFocusReleased

Globals don’t replicate and shouldn’t be used in regular development anyhow. Please also read documentation before linking it.

The UserInputService WindowFocused event fires when the window of the Roblox client gains focus - typically when the Roblox client is maximized/actively open on the user’s screen.

The server doesn’t have a concept of an maximised window.

1 Like

Oh then just use a remotevent easy

OP addressed this and says they don’t want to (for some reason?). That’s why I want to know what OP’s exact use case is and why remotes aren’t good enough. The server shouldn’t need to determine this information but apparently they need it to.

1 Like

Instead of checking if the player/exploiter is afk, why not check if they’re using exploits instead? The anti afk is not the problem, the hacks are.

local UIS = game:GetService("UserInputService")

UIS.WindowFocusReleased:Connect(function()
    -- Do whatever here.
end)

UIS.WindowFocused:Connect(function()
    -- Do whatever here.
end)
1 Like

The server-side solution to this is to verify whether the player is doing something, instead of trusting the client to tell the truth (as you do right now).
Check whether the player character has moved any distance, chatted, used any tool/fired any remotes that are only fired by player actions etc.

Exploiters (and some legit players) will still be able to do things that don’t count as AFK while still counting as AFK, so be thorough.

Do not have a “I did something” remote because exploiters will simply delete it and stay AFK while walking or something. Just make your AFK checking script connect to the same remotes everything else uses.

Players might push others around to “wake” them to troll them if being AFK is so lucrative (I don’t know your game), but this isn’t a pressing issue.

There is also no good way to know if a player is not AFK because it is very easy to automate your computer to do something on a timer. I’ve done that on Minecraft servers, for example.