I don’t know if there is any way to make a script that prevents the 20 AFK kick. But one way it can be done with external software is, you can use a keyboard macro, or autoclicker to make roblox think that the player isn’t AFK, and then the player won’t get kicked for being AFK.
Instead of trying to teleport the player back into the same server, use :ReserveServer() and simply create a new server for the player to teleport into. The old one will close, and the player will be unaffected if AFK.
This is different from just teleporting the player back into the game, since you don’t want them joining the starter place and sticking around. You need to specifically reserve a server in the AFK place.
Are you testing this as just yourself? Because when you rejoin, the old server gets shut down immediately when the last player leaves. Thus, if you are the only one playing the game, it will lead to a shutdown message. If you have other player’s in the game, then it should successfully reconnect them.