I want to make it so that when a player hits a button, they get teleported into a reserve server(a match making service, if you will).
No matter what GameID I use, it says “Error: Attempted to teleport to a restricted place”. It also says in the developer console: “Teleport failed due to invalid server code.”
I’ve tried switching the GameIDs, and copying the direct code from the DevsHub page, with no success.
Notes: I have permissions to get to the game, but it still fails to work. I am trying this in a private place, so would this be the issue?
-- Server sided code
local TS = game:GetService("TeleportService")
local code = TS:ReserveServer(game.PlaceId) -- Returns a code
local players = game.Teams.Queue1v1:GetPlayers()
TS:TeleportToPrivateServer(game.PlaceId, code, players)
I tried the DevHub code on a public game and it worked out of the box for me. It might actually be the place being private? A game should always be able to reserve a server for itself and teleport players within that, last I checked.
--/ Services \--
local TeleportService = game:GetService("TeleportService")
--/ Variables \--
local Code = TeleportService:ReserveServer(game.PlaceId)
local Players = game.Teams.Queue1v1:GetPlayers()
--/ Main Code \--
TeleportService:TeleportAsync(game.PlaceId, Players, Code)
Your problem was initially you were getting a reserved server, then teleporting to a private server, resulting in confusion. This should work, let me know if otherwise.
TeleportToPrivateServer, although deprecated, is a function that teleports to reserve servers. You’re using
TeleportAsync incorrectly in this suggestion - the third argument is meant to be a TeleportOptions object, which contains the
ReservedServerAccessCode. So, @Ggblocks20 would use:
-- ... stuff from before ...
local teleportOptions = TeleportOptions.new()
teleportOptions.ReservedServerAccessCode = Code
TeleportService:TeleportAsync(game.PlaceId, players, teleportOptions)
Try this which uses the new TeleportAsync:
local TeleportService: TeleportService = game:GetService("TeleportService")
local PlaceID: number = game.PlaceId
local Players = game:GetService("Teams").Queue1v1:GetPlayers()
local TeleportOptions: TeleportOptions = Instance.new("TeleportOptions")
TeleportOptions.ShouldReserveServer = true
TeleportService:TeleportAsync(PlaceID, Players, TeleportOptions)
Let me know if this helps
Doesn’t seem to work, gives me a “cannot cast value to object error”, on the
So Teleport options is the supported version of Teleport to private server? I never knew it was deprecated…
It managed to work, thanks to everyone who helped!
Yes it is the newer version, but it is not yet deprecated. Almost a year ago, Roblox said they would deprecate it at some point, but as of right now, it is just a legacy method that Roblox doesn’t recommend.
Yeah, TeleportToPrivateServer and TeleportAsync have different parameters.