Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why does my Tp to private server script not work?

Asked by
Uluomis 32
5 years ago
Edited 5 years ago

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?

1local TS = game:GetService("TeleportService")
2local Players = game:GetService("Players")
3local players = Players:GetPlayers()
4local ClickDetector = script.Parent
5local code = TS:ReserveServer()
6 
7ClickDetector.MouseClick:Connect(function()
8    TS:TeleportToPrivate(3926134089,code,players)
9end)
0
TeleportToRese? royaltoe 5144 — 5y
0
Wait is this on a gui? Or is it a brick voidofdeathfire 148 — 5y

1 answer

Log in to vote
2
Answered by
sasial 26
5 years ago

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:

01local TS = game:GetService("TeleportService")
02local Players = game:GetService("Players")
03local DSS = game:GetService("DataStoreService")
04local DS = DSS:GetGlobalDataStore()
05local ClickDetector = script.Parent
06 
07-- Get the saved code
08local code = DS:GetAsync("ReservedServer")
09if type(code) ~= "string" then -- None saved, create one
10    code = TS:ReserveServer(game.PlaceId)
11    DS:SetAsync("ReservedServer",code)
12end
13 
14ClickDetector.MouseClick:Connect(function(plr)
15    TS:TeleportToPrivateServer(game.PlaceId,code,{plr})
16 end)
0
This is the best answer. Do this OP sahadeed 87 — 5y
0
This is the best answer. Do this OP sahadeed 87 — 5y
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? Uluomis 32 — 5y
Ad

Answer this question