AFK System help

I have written a script in charge of teleporting players to a place in this “universe”. However, I just implemented an AFK system and need help on how to go about writing a code.
Currently, the GUI that lets you go AFK changes a value in the Player (not character, just player) to true, (the value is called AFK)

Here is the current version of the script:

while wait(60) do
	local TS = game:GetService("TeleportService")
	local Players = game:GetService("Players")
 
	local code = TS:ReserveServer(6695412415)
	local players = Players:GetPlayers()

	TS:TeleportToPrivateServer(6695412415, code, players)

end

I have a feeling it has something to do with in pairs, but I have no clue what any of the tutorials mean. How would I go about implementing this?

Also, here’s a clip of the game prior to right now:

1 Like

Since TeleportToPrivateServer requires an Array of players, what we can do is create our own Array & that’ll detect all the non-AFK players like so I believe:

while wait(60) do
    local ActivePlayers = {}
	local TS = game:GetService("TeleportService")
	local Players = game:GetService("Players")
 
	local code = TS:ReserveServer(6695412415)
	for _, Player in pairs(game.Players:GetPlayers()) do
        if Player.AFK.Value == false then
            table.insert(ActivePlayers, Player)
        end
    end
	TS:TeleportToPrivateServer(6695412415, code, ActivePlayers)

end

Thanks, let’s see if it works…

Unfortunately, it appears to not work.