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)
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.
1) The precedence of the
CurrentGame
does not have to beActive
2) The precedence of the
OtherGame
does all have to beActive
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
[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 justWorkspace
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.