HTTP 403 Forbidden

local players = game:GetService("Players")
local ts = game:GetService("TeleportService")

local code = ts:ReserveServer(game.PlaceId)
local player = players.GetPlayers()

function leftClick()
    ts:TeleportToPrivateServer(game.PlaceId,code,players)
end

script.Parent.MouseButton1Click:Connect(leftClick)

Console Error:
HTTP 403 Forbidden

What is the meaning of this?

1 Like

I switched to LocalScript but now I am getting:

TeleportService:ReserveServer can only be called by the server

1 Like

It’s just as it says. ReserveServer can only be used by the server, so you need to be using remotes here. In addition, for the player thing, not only is it being called incorrectly but it is also going to gather all players in the server into a table and teleport everyone. If your intention is just to teleport one player, you’ll need a way to designate that. Remotes can help there too.

From the server side, you’ll be reserving a server and teleporting a player to it. All the client is going to do is request the server to carry out the action because it wishes to join a private server.

I can give you a crude sample but adapting it to your own implementation is up to you.

Client-side:

local function leftClick()
    remoteEvent:FireServer()
end

script.Parent.MouseButton1Click:Connect(leftClick)

Server-side:

local TeleportService = game:GetService("TeleportService")

local function serverReceiveEvent(player)
    local reserveCode = TeleportService:ReserveServer(game.PlaceId)
    -- Players must be a table; make single-entry table of player to
    -- teleport only them to the reserved server.
    TeleportService:Teleport(game.PlaceId, reserveCode, {player})
end

remoteEvent.OnServerEvent:Connect(serverReceiveEvent)
3 Likes

It appears that you made a typo, because the players variable is defined as the Players service. I believe you meant to type player. Also the player variable is defined as players.GetPlayers() when it should be players:GetPlayers()

heres the fixed code:

local players = game:GetService("Players")
local ts = game:GetService("TeleportService")

local code = ts:ReserveServer(game.PlaceId)
local player = players:GetPlayers()

function leftClick()
    ts:TeleportToPrivateServer(game.PlaceId,code,player)
end

script.Parent.MouseButton1Click:Connect(leftClick)

1 Like