For anyone wondering, the way Kavra’s Kingdom set up their afk room was by making the player rejoin
they posted it 11 months ago hahahaha it wasn’t 2019 11 months ago…
and YES you do get an error when using the script HOWEVER it does still work regardless of the error… test yourself here: AFK SQUARE - Roblox I setup an afk square to test it.
funny, cause its working fine for me
^^ anti-afk game… you can stand in the square forever without getting kicked for inactivity.
I never said it didn’t work, only that it doesn’t work, well, well
Ye ik, am just saying it still works for this method… it just doesn’t work anymore well for actually controlling the characters/client… but it will still give enough fake input to stop the game from idling a player.
Yeah sorry I am not quite used to the forum, so I see Apr 19 and I am thinking the wrong thing.
Anyhow I tested your place and it did seem to work, I checked after 10 minutes of being in the AFK square and I had a bunch of errors popping up in console, in a spam like fashion all in an instant, a screen worth. So I left it another 22 minutes, switched back to it and I hadn’t been kicked, however the Roblox client crashed on me about 5 seconds later when I was trying to open the console again, maybe due to the spam?
Do you need to spam the clicks for it to work, or is a single fake click at 19 minutes of AFK time enough? Whatever the answer is to that the fact these errors come up, and can even crash the client make it a bit of an icky solution IMO, but it is worthwhile to know it can work.
haha no worries, ik their format/layout takes some getting used to.
anyway, unfortunately there is no way to stop the errors entirely as the error occurs because you cant simulate a click from server OR client…
but this is ok because its not the “click” that stops the idling, its the “attempt” to click that stops it.
as for crashing, if you don’t do it in a loop and just do
game:GetService("Players").LocalPlayer.Idled:connect(function()
game:GetService("VirtualUser"):ClickButton2(Vector2.new())
end)
instead then there is less errors and less chance of your client crashing.
So I tried it in my own game and it doesn’t work. I tried multiple things
- Clickbutton2 once every 17 minutes
- Clickbutton1 and Clickbutton2 every minute
- Clickbutton1 and 2 in the idled event. I thought maybe the error in Idled event may be blocking the AFK code
All resulted in being kicked after 20 mins idle.
My game has no player characters, but Idled was stilled called every 2 minutes or so. But yeah, it appears not to work for me. The teleport trick does work for me at least.
This code is pretty horrible because it creates a new Idle connection every wait() among other things.
Here is a better version, it detects when a player stops inputting, waits 1199 seconds, then clicks and breaks itself whenever the player starts inputting.
local UserInputService = game:GetService("UserInputService")
local elapsed = 0
UserInputService.InputBegan:Connect(function()
if connection then
connection:Disconnect()
connection = nil
elapsed = 0
end
end)
UserInputService.InputEnded:Connect(function()
local connection
connection = game.RunService.Heartbeat:Connect(function(delta)
elapsed += delta
if elapsed >= 1199 then
game:GetService("VirtualUser"):ClickButton2(Vector2.new())
elapsed -= 1199
end
end)
end)
Here’s a slightly shorter version:
local UIS = game:GetService("UserInputService")
local elapsed = 0
UIS.InputBegan:Connect(function(input) elapsed = 0 end)
game:GetService("RunService").Heartbeat:Connect(function(delta)
elapsed += delta
if elapsed >= 1199 then
game:GetService("VirtualUser"):ClickButton2(Vector2.new())
end
print(math.floor(elapsed))
end)
I don’t know if this doesn’t work, or if it makes your game lag, but just try it out nevertheless.
I didn’t try the code posted here originally because it is broken like bytesleuth said. None of my methods worked which I described here already. It could be the combination of my game having no player character, or, unless you do it in the broken manner (which seems to crash client eventually) it doesn’t “work”.
I did something similar to your code here and it doesn’t work. I tried shortening the idle elapsed to 1 minute also and it didn’t work either.
Maybe adding so many connections to Idled (in the broken code) does somehow end up breaking the AFK routine, not sure, but that is not reliable code.
The most reliable would be to just teleport the player out and back into the game every 17 mins of being afk. If you want to make this even better then teleport them to the same server and teleport the player model in their last position
A major downside to the teleport method is if the player is in a server with only one player it won’t reconnect. ie If they are in a private server playing solo it won’t work. Unless there is a work around for that?
You can use TeleportService for this, it really is the only way. Also, the service has a 4th parameter for a customLoadingScreen
, so you can let the player know they’ll be teleported back very shortly.
For the one-player server issue, my best bet is to just set Roblox’s default server fillup option to “Fill up as many servers as possible”.
A custom loading screen for absent people? Not sure how useful that is.
Most of my players seem to play on servers with other people but I currently allow them to play on their own server. When I try it myself as a dev on my own place, teleporting back to the same place (even without a specific instanceid set) it says “server has disconnected” after the attempted teleport, then the option to quit or reconnect appears.
I played around a bit with TeleportOptions but couldn’t find a configuration which created a server if all were empty, or the one it anticipated going to closed down.
Something I’ve tested in the last 6 hours is the following does seem to work for single player reconnects and avoiding the AFK timeout.
local teleportData = {whatever you need here}
local teleportOptions = Instance.new("TeleportOptions")
teleportOptions.ShouldReserveServer = true
teleportOptions:SetTeleportData(teleportData)
and
success, result = pcall(function() return game:GetService("TeleportService"):TeleportAsync(game.PlaceId, { Player }, teleportOptions) end)
Though sometimes even though it does appear like the game is running in the background, when I finally switch to it, it seems to do another teleport too, though it is hard to predict it exactly. But overall I think it works better than just kicking AFK players in my game. I will put it into live production soon.
All it essentially does it teleport the player to the same game they’re playing in.
If you’re AFK at a spot, then you get teleported in 19 minutes, you’ll just be back at the spawn point, or if progress is involved, that’ll be cleared.
You’d want to pass on some launch data to the teleport service, telling them where they were AFK, and to give back the progress they had.
I really agree on this, in the game Space Sailors If you launch and decide to go to the moon, you can do an optional 3 day challenge because of the realistic time it takes to get to the moon in Translunar Injection (~3 days) so you would need an autoclicker to stop the player from getting kicked. but if there was a way to disable this by using a script, then it would be better as players wouldn’t have to be using an autoclicker.
This is hacky. But the player can still leave on their own so ig it works.