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

How to teleport a player to another game?

Asked by 6 years ago

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)
0
did u put the game id? User#22145 0 — 6y
0
of course i did XD lolkid007 43 — 6y
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? User#5423 17 — 6y
0
Use remote events. Connect the script two when the event is fired from the dialog and it should work. Zafirua 1348 — 6y
View all comments (3 more)
0
how would I implement that into my code? lolkid007 43 — 6y
0
Updated the code. Check it out. Zafirua 1348 — 6y
0
where lolkid007 43 — 6y

1 answer

Log in to vote
2
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
6 years ago
Edited 6 years ago

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

2) The precedence of the OtherGame does all have to be Active

3) 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

2) Insert Script1 in just Workspace

3) 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.

Ad

Answer this question