My script to teleport people to a reserved server of a sub-game isn't working:
while true do print("Running") wait() local TS = game:GetService("TeleportService") local Players = game:GetService("Players") local code = TS:ReserveServer(8357468682) local players = Players:GetPlayers() TS:TeleportToPrivateServer(8357468682,code,players) end
It's a normal script in workspace, I'm so confused
ReserveServer
& TeleportToPrivateServers
are both functions that are not recommended to be used anymore. ROBLOX has released a more recent multi-use function in TeleportService
called TeleportAsync
(DevWiki) which should be used instead.
Here is a revised version of your code which uses it and should work. Note that I would not recommend using a while
loop as it will constantly just teleport them. Put it in a function and call it when you need it.
local TeleportService = game:GetService("TeleportService") local Players = game:GetService("Players") while true do print("Running") wait() local teleportOptions = Instance.new("TeleportOptions") teleportOptions.ShouldReserveServer = true local players = Players:GetPlayers() if #players >= 1 then local teleportResult = TeleportService:TeleportAsync(game.PlaceId, players , teleportOptions); -- print(teleportResult.ReservedServerAccessCode); -- You can access the reserved server access code using this. end end
So I modified game.PlaceId to my sub-place is what I call it (8357468682) yet it still doesn't work! I put it in a normal script in workspacee and this is the error I got
" 11:32:27.874 HTTP 403 (Forbidden) - Server - Script:13"
local TeleportService = game:GetService("TeleportService") local Players = game:GetService("Players") while true do print("Running") wait() local teleportOptions = Instance.new("TeleportOptions") teleportOptions.ShouldReserveServer = true local players = Players:GetPlayers() if #players >= 1 then local teleportResult = TeleportService:TeleportAsync(8357468682, players , teleportOptions); -- print(teleportResult.ReservedServerAccessCode); -- You can access the reserved server access code using this. end end