Help with teleport between places in roblox

  1. What do you want to achieve? I want to teleport between places in my game on button click with error handle

  2. What is the issue? It just doesn’t teleport me, doesn’t give me any errors

  3. What solutions have you tried so far? I tried this

local pb = script.Parent.Play
local Player = game.Players.LocalPlayer
local TeleportService = game:GetService("TeleportService")
local TARGET_PLACE_ID = 10331222528
local ServerScriptService = game:GetService("ServerScriptService")

local function handleFailedTeleport(player, teleportResult, errorMessage, targetPlaceId, teleportOptions)
	if teleportResult == Enum.TeleportResult.Flooded or teleportResult == Enum.TeleportResult.Failure then
		-- pause and retry if it's a one-time hiccup
		-- teleportOptions automatically have the reservedServerCode filled up
		TeleportService:TeleportAsync(TARGET_PLACE_ID, Player, teleportOptions)
		-- throw an error if something else is wrong
		error(("Invalid teleport [%s]: %s"):format(teleportResult.Name, errorMessage))


local function play() -- play button (level 0 teleport)
	TeleportService:TeleportAsync(TARGET_PLACE_ID, Player) 


Have you tried it on Studio or in the ROBLOX place?

I tried in the Roblox place. It doesn’t work.

We might know the problem.

Go to your place again, press F9 on your keyboard and the developer console will show up, once that is done, click the server button in the right-top of the console, and chrck for some errors or prints.

If you are already aware of this, check it out.

Also, is your script a local script?

1 Like

Yes. Local scipt in Starter Gui

1 Like

Error in this line “Unable to cast value to Objects”
TeleportService:TeleportAsync(TARGET_PLACE_ID, Player)

Ah I see.

Instead of TeleportAsync, change it to Teleport(targetID, {player})

1 Like

Its work. Thank you so much!!!

1 Like

No problem! Glad it worked :clap:, Good luck on your project tho.

1 Like