Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why does my Tp to private server script not work?

So I was trying to make a script based off the Roblox developer website (https://developer.roblox.com/en-us/api-reference/function/TeleportService/TeleportToPrivateServer) that TPs players to a private server that no one else can join (like in camping 1 and 2) when a brick is clicked and it wouldn't work. I know the problem is the reserve server code argument and have tried to fix it in many ways but it doesn't seem to work. Can someone please fix it for me?

local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
local players = Players:GetPlayers()
local ClickDetector = script.Parent
local code = TS:ReserveServer()

ClickDetector.MouseClick:Connect(function()
	TS:TeleportToPrivate(3926134089,code,players)
end)

2 comments

0

TeleportToRese?

0

Wait is this on a gui? Or is it a brick

1 answer

The following code would reserve one server if it hasn’t be reserved before. Whenever clicks the ClickDetctor he/she will be teleported to the private server:

local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
local DSS = game:GetService("DataStoreService")
local DS = DSS:GetGlobalDataStore()
local ClickDetector = script.Parent
 
-- Get the saved code
local code = DS:GetAsync("ReservedServer")
if type(code) ~= "string" then -- None saved, create one
	code = TS:ReserveServer(game.PlaceId)
	DS:SetAsync("ReservedServer",code)
end
 
ClickDetector.MouseClick:Connect(function(plr)
	TS:TeleportToPrivateServer(game.PlaceId,code,{plr})
 end)

3 comments

0

This is the best answer. Do this OP

0

This is the best answer. Do this OP

0

So I tried this but replaced game.PlaceId with 3926134089 on line 15. Got the Error code 769 when teleporting what should I do?

This discussion is preserved as it was. New answers, comments, and votes are closed.