I’m trying to make a private server button because when you join my game it’s actually a menu that has play button to teleport to a place where the actual game is, and I made the “Private Server” button for people to be able to grind in private server easily but when I teleport a person to the reserved server it somehow teleports them back to the public server and I don’t know why, here’s the code for teleporting the person:
prompt3.OnServerEvent:Connect(function(player)
local reservedServer = tpservice:ReserveServer(17066404164)
local loadingscreen = game:GetService("ServerStorage").TeleportGUI:Clone()
tpservice:TeleportToPrivateServer(17066404164, reservedServer, {player}, nil, nil, loadingscreen)
end)
On the documentation, it is recommended to use TeleportAsync instead of TeleportToPrivateServere for this scenario.
You can add teleportOptions to create a new reserved server without needing to create a new one.
Sample code:
local tpservice = game:GetService("TeleportService")
local ServerStorage = game:GetService("ServerStorage")
local prompt3 -- set this to wherever prompt3 is
prompt3.OnServerEvent:Connect(function(player)
local teleportOptions = Instance.new("TeleportOptions")
-- Setting ShouldReserveServer to true will automatically create a ReservedServer and teleport the provided players to the server when TeleportAsync is called with the TeleportOptions
teleportOptions.ShouldReserveServer = true
-- it is highly recommended that you add error handling with a pcall.
-- For more info on handling failed teleport, see https://create.roblox.com/docs/projects/teleporting#handling-failed-teleports on the Creator Docs
tpservice:TeleportAsync(17066404164, { player }, teleportOptions)
end)
To set the teleport gui, see the instructions for this method on the documentation: