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

Why is this basic TeleportService script not working?

I started with a script I found on the roblox website on the page for TeleportService:TeleportToPrivateServer, and changed it to my ids. Sorry if this is a basic, mistake, I am new to scripting. The code should teleport the player to a separate game, but it does nothing.

local TS = game:GetService("TeleportService")
local Players = game:GetService("Players")
 
local code = TS:ReserveServer(4456038439) -- Returns a code
local players = Players:GetPlayers() -- Get a list of all players
 
TS:TeleportToPrivateServer(4456038439,code,players) -- Actually teleport the players

2 answers

✓ Accepted answer
local TeleportService = game:GetService("TeleportService")
local gameID = 00000000 -- put the second game's game ID here.
 
function onTouched(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        TeleportService:Teleport(gameID, player)
    end
end
 
script.Parent.Touched:connect(onTouched)
-- This is just a simple teleport that teleports you to another game seprate on roblox, No API's or other vip stuff.
-- IMPORTANT: You cannot teleport to other games within studio.

This should work

2 comments

0

Thanks, modified it a bit to use TeleportService:TeleportToPrivateServer and discovered that to do that the other game requires to be a place in the game that you were teleported from; thanks for the code by the way, easy to modify off of.

0

np

use this if your teleporting every player. the answer above only works when touching a part.

local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")

local gameID = 0 -- gameid here
local code = TeleportService:ReserveServer(gameID)

for _,players in pairs(Players:GetPlayers()) do
     if players:IsA("Player") then
        TeleportService:Teleport(gameID,code,players)
     end
end

3 comments

0

Thanks, this works too!

0

:( i wasnt accepted

0

I really dont mean to beg, but can u consider taking a look at my issue if its not too much of a hassle (litreally no errors but it dont work) https://scriptinghelpers.org/questions/91802/stat-will-not-add-onto-a-players-speed-along-with-another-number-and-my-coin-wont-collect-properly

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