Teleport not working [v2]

I have already made a post here but now I have another issue. Can someone fix this script as it is not working?

local Clicked = false
local Player = game.Players.LocalPlayer
local TeleportService = game:GetService("TeleportService")
local GameId = 5160406096
local object = script.Parent.Parent.Parent.Blackout.Frame

object.AnchorPoint = Vector2.new(0,0)
object.Position = UDim2.new(1, 0, 0, 0)
object.Visible = true



script.Parent.MouseButton1Down:Connect(function()

	game.ReplicatedStorage.OtherSounds.Click:Play()
	object.BackgroundTransparency = 0
	object:TweenPosition(UDim2.new(0,0,0,0), Enum.EasingDirection.Out, Enum.EasingStyle.Bounce)
    wait(0.5)
    TeleportService:Teleport(GameId)
end)

If you put print("clicked") under that script.Parent.MouseButton1Down:Connect(function() line, does it print when you click the button?

Are you running this in studio or a live game server?

Now that I’m looking at your code, it looks like you’re giving the :Teleport method the GAME id, not the PLACE id. Open the “Game Explorer” from the View tab in Studio and open the “Places” folder. Right click the place you want to teleport them to and click the “Copy place id” button and use that instead.

2 Likes

It is supposed to tp you from the place to the main game

1 Like

The steps I have at the end should still solve your problem. Roblox does not know which place to teleport them to if you just give the game ID - games can have multiple places.

3 Likes

You forgot the argument of Player in the :Teleport().
It is supposed to be :Teleport(gameId, player).
Read about it here.

1 Like

So it is supposed to tp you from Rock Collecting (A place) to Science World (The main game), is this possible?
Screen Shot 2020-08-25 at 3.34.31 pm

Right click the “Science World”, select “Copy Place ID”, replace your gameid variable with placeid and use the copied ID instead.

1 Like

Do I need to add GameId, Player like @XDvvvDX said?

1 Like

It is required when you use :Teleport(). How will it know what player to teleport (I am talking about the second argument)?

Is this the script? Will it work fine?

local Clicked = false
local Player = game.Players.LocalPlayer
local TeleportService = game:GetService("TeleportService")
local PlaceId = 5160406096
local object = script.Parent.Parent.Parent.Blackout.Frame

object.AnchorPoint = Vector2.new(0,0)
object.Position = UDim2.new(1, 0, 0, 0)
object.Visible = true



script.Parent.MouseButton1Down:Connect(function()

	game.ReplicatedStorage.OtherSounds.Click:Play()
	object.BackgroundTransparency = 0
	object:TweenPosition(UDim2.new(0,0,0,0), Enum.EasingDirection.Out, Enum.EasingStyle.Bounce)
    wait(0.5)
    TeleportService:Teleport(PlaceId, Player)
end)
1 Like


You do not need to specify the player since you’re calling it from the client. You do need the place id though, not the game id.

2 Likes

If he calls it from the client the server won’t see it. @Ulxqra I suggest you use RemotEvents and teleport the player from the server.

So would that script work finely?

1 Like

Indeed this script should work for you.

You do not need to use RemoteEvents for this to work. It will work perfectly fine as-is.

2 Likes

When I changed the variable name to PlaceId, arn’t I just changing the variable name?

1 Like

Yes, I said if he wants it to call from the server than he should use RemoteEvents.

You are only changing the variable’s name, this isn’t necessary, I am typing you an example script right now.

Ill send some vid proof of whats the issue.

1 Like

Here’s a code example:

local button = script.Parent;

local gameId = 0 -- Change it to your game ID.

local function on_Click()
	
	local teleportService = game:GetService("TeleportService");
	
	local succed, stringError = pcall(function()
		
		teleportService:Teleport(gameId, game.Players.LocalPlayer)
	end)
	
	if succed then
		
		warn("Succed to teleport player.")
	else
		warn("Failed to teleport player: ".. stringError)
	end
end

button.MouseButton1Click:Connect(on_Click)