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

How to teleport a player to another game?

I have two scripts. One is supposed to activate the other when a dialog choice is selected. The other is supposed to teleport the player. The first script works fine but the second script doesn't want to work. Script One:

local dialog = script.Parent
local activateScript = game.Workspace.Teleport

dialog.DialogChoiceSelected:connect(function(player, choice)
    if choice == script.Parent.RightChoice then
		wait(2)
        activateScript.Disabled = false --Activated Script
    end
end)

Script Two:

local TeleportService = game:GetService("TeleportService")
local level1Id = --game ID
local player = game.Players.LocalPlayer

TeleportService:Teleport(level1Id, player)

7 comments

0

did u put the game id?

0

of course i did XD

0

If you are teleporting through a local script you do not add the player. I am not sure if the second script is a local script?

0

Use remote events. Connect the script two when the event is fired from the dialog and it should work.

0

how would I implement that into my code?

0

Updated the code. Check it out.

0

where

1 answer

✓ Accepted answer

Since there are no particular errors to you code, you will have to re-check the code using my evaluation guidelines.

1) Check whether the teleporting place is the starting place of the another main game.

Since you explicitly pointed out, "Another Game", it is assumed that the destination is a completly different game and not a precedence of the current game.

Criteria

  1. The precedence of the CurrentGame does not have to be Active
  1. The precedence of the OtherGame does all have to be Active
  1. The teleportation does not work unless you are referencing the OtherGame's starting place.

CurrentGame := The game you are using to teleport the player.

OtherGame := The destination. MUST BE A STARTING PLACE AND ACTIVE

2) If you have checked the above criteria and the error still persists, then wait for the player to fully load.

3) Make sure that the place id you put is of the starting place id and is active. Also the place id Cannot be a string.

4) Teleportation does not work in Studio and make sure the game is actually published.

[EDIT] @Kingdom5 provided an interesting comment saying that the LocalPlayer does not need to be defined. I honestly do not believe that but you can still try it out.

[EDIT] The reason is because you are not connecting the code. We will use RemoteEvents for this.

  1. Insert a Remote Event in ReplicatedStorage
  1. Insert Script1 in just Workspace
  1. Insert Script2 in the dialog.
-- [Script1]

-- Declaration Section
local Workspace = game:GetService("Workspace") 
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Target = Workspace:FindFirstChild("Part")
local TeleportPlayerEvent = ReplicatedStorage:WaitForChild("TeleportPlayer")

-- Processing Section 

local function TeleportPlayer (player)
	if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
		player.Character.HumanoidRootPart.CFrame = Target.CFrame + Vector3.new(0, 5, 0)
		wait()
		print("The player has been teleported")
	end
end

-- Connecting Section 

TeleportPlayerEvent.OnServerEvent:Connect(TeleportPlayer)
-- [Script 2]

-- Declaration Section 
local Workspace = game:GetService("Workspace")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportPlayerEvent = ReplicatedStorage:WaitForChild("TeleportPlayer")

local Dialog = script.Parent 

local function TeleportPlayerWhenClicked (player, choice)
	if choice == script.Parent.Choice1 then
		TeleportPlayerEvent:FireServer()
		print("Fired Server")
	end
end

Dialog.DialogChoiceSelected:Connect(TeleportPlayerWhenClicked)

Let me know if the error still persists.

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