AFK System help part 2

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 original 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

Then, I tried out this script.

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

Apparently, I get a HTTP 403 error here:

local code = TS:ReserveServer(6695412415)

BEFORE YOU SAY ANYTHING, I HAVE ALREADY ENABLED HTTP REQUESTS AND THIRD-PARTY TELEPORTS.
I do not understand what is occurring here. I have had HTTP 403 errors in the past, but never like this.
Please help.

Have you tried to print ‘ActivePlayers’?

This looks fine to me.

I edited just now, please read that.

1 Like

403 indicates that the server rejected your request (more info here: HTTP 403 - Wikipedia). So basically, your code does not have permission to do what you want.

In the documentation of TeleportService | Roblox Creator Documentation, I found: “If a teleportation request is rejected the TeleportService.TeleportInitFailed event will fire the error message and a TeleportResult enumerator describing the issue”. Maybe you can check what that event returns and inspect the issue.

How would I go about implementing this into the code?

Here is an example: TeleportService | Roblox Creator Documentation. As you can see, there is a connection with the event before the teleport action is made.

I still don’t exactly understand.

Can you try this?

local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")

TS.TeleportInitFailed:Connect(function(player, result, errorMessage)
    if result == Enum.TeleportResult.Failiure then
        error(player, errorMessage)
    end
end)

while wait(60) do
	local ActivePlayers = {}

	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

I don’t think you understand.
This line of code is giving an HTTP 403 error.

local code = TS:ReserveServer(6695412415)

I’m not getting the InitFailed message either.

Forget it. I might as well just revert back to the old version.

Are you making the tests on studio, or through the Roblox app?

Are you testing this in studio, cause the documentation says: “This service does not work during playtesting in Roblox Studio — To test aspects of your game using it, you must publish the game and play it in the Roblox application.”

Both. Neither work.
I know Studio isn’t supposed to work, but Player does not either.

If you want a working version of the game, here it is:
https://www.roblox.com/games/6695085461/Scoobis-Containment?refPageId=69104533-1b69-41b4-b7d2-f3d4bc344449
its loads of fun
free advertising lol

I did some more research and I found these are the only reasons for it to not work:
"

Teleport failure

In some circumstances a teleport may fail. This can be due to the developer configuring the teleport incorrectly or issues with Roblox’s servers.

  • If a teleportation request is rejected the TeleportService.TeleportInitFailed event will fire the error message and a TeleportResult enumerator describing the issue

  • Teleports can fail ‘in transit’, after the user has left the server, due to issues with Roblox’s servers. In this case the user will be shown an error message and be required to rejoin the game

Studio limitation

This service does not work during playtesting in Roblox Studio — To test aspects of your game using it, you must publish the game and play it in the Roblox application."

Thanks. It doesn’t matter. The game doesn’t need one anyways.