I have been using the code below, and after being Idle and not on the Roblox window for well over 5 minutes, it still has not printed anything. Am I doing something wrong?
local player = game.Players:WaitForChild("Volieb")
player.Idled:Connect(function(seconds)
print("Time: "..seconds)
end)
Note: I am not doing this in Roblox Studio, I am doing it via the Roblox client.
I feel like this might just come down to the case that Idled is unreliable to be using. Luckily, there is a way to keep track of it the player is Idle by keeping track of their inputs via UserInputService.
local idle = false
local timer = 0
UIS.InputEnded:Connect(function()
idle = true
while wait(1) do
timer += 1
if not idle then
break
end
if timer >= 180 then
localPlayer:Kick("Been afk for 3 minutes")
break
end
end
end)
UIS.InputBegan:Connect(function()
idle = false
timer = 0
end)
Probably more friendlier ways to handle this than through a while loop, but you can see the basic principles.
Well, I wouldn’t want to handle it throught the client. I am making this for a hotel game, and I am tyring to kick staff if they go AFK for over a certain amount of time, due to people staying AFK just to have their activity boosted. So, this could be easily bypassed since it is on the client.
Gottya, I guess I will just use Idled but through the client. I don’t think it is that big of a deal if someone bypasses it somehow. Thank you for your help!
You could do this by starting a countdown everytime there is no input on the client via a local script and resetting the countdown everytime the presses anything on their keyboard or moves their mouse, the only way to get around this would be using an exploit, which I assume your "workers’ would not use.