How to script a button to teleport you to another game

Okay so I tried making it and every time I try it says this as the error. I am not sure what I am doing wrong.

image

local Teleport = game:GetService("TeleportService")
local GameID = 7256016202
local Players = game.Players.LocalPlayer


script.Parent.MouseButton1Down:Connect(function()
	Teleport:Teleport(GameID, Players)
	
end)

What is my error?

2 Likes

You probably want to teleport the player on a server script instead. To do that, you want to have a RemoteEvent in this situation. In your LocalScript, you want to fire the remote event when a player clicks/taps on the button, by using the function FireServer(). Then you do the teleport stuff on a server script by first calling the OnServerEvent function.

Confirm that you have the correct Place Id. Otherwise it may not work at all. And also, the game you want players to teleport MUST be your game, or else it will not allow you to join that place at any given cost.

2 Likes

Yes it is, and it still shows up the error.
image
– Proof that this is the ID.

2 Likes

I converted it into a Remote event, then fired it inside of a Local Script. The error still shows.

1 Like

Is your place part of your game? Like is the place attached to your current game?

2 Likes

No it isn’t. They are separate games.

2 Likes

2 Likes

Hmm. Thats strange. I believe it should have worked by now. Could you show your current local script and server script?

2 Likes

Sure.

ServerScriptService Script


local TeleportEvent = game.ReplicatedStorage.Teleport
local Teleport = game:GetService("TeleportService")
local GameID = 7256016202
local Players = game.Players.LocalPlayer

TeleportEvent.OnServerEvent:Connect(function()
	Teleport:Teleport(GameID, Players)
end)

Local Script

script.Parent.MouseButton1Down:Connect(function()
	game.ReplicatedStorage.Teleport:FireServer()
end)
2 Likes

You cant access the local player on a server script. That can only be accessed on a LocalScript.
To get the actual player who clicked/tapped on the button, you just want to add player or something in the paranthesis in the OnServerEvent as the first argument.
Use this code for your server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Teleport = game:GetService("TeleportService")

local TeleportEvent = ReplicatedStorage:WaitForChild("Teleport")
local GameID = 7256016202

TeleportEvent.OnServerEvent:Connect(function(plr)
	Teleport:Teleport(GameID, plr)
end)
2 Likes

There’s no need for a RemoteEvent if you’re teleporting the LocalPlayer in the LocalScript. Check if teleporting players to third-party games in the game settings is enabled.

If the placeId is certainly correct, and you have implemented any other scripts or models, check if they’re interfering with this.

2 Likes

Just tried, except this time the error doesn’t show at all. But I do not get teleported.

They are enabled. And remote events should work aswell.

Were there any errors in the output?

I think I found the issue.
Try using this code for your server script:

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local TeleportService = game:GetService("TeleportService") -- Renamed variable to 'TeleportService', cuz the problem was that you put 'Teleport' as the variable name, and thats the exact name for the "Teleport" function

local TeleportEvent = ReplicatedStorage:WaitForChild("Teleport")
local GameID = 7256016202

TeleportEvent.OnServerEvent:Connect(function(plr)
	TeleportService:Teleport(GameID, plr) -- teleports player who clicked/tapped the button
end)
2 Likes

The problem is that you named the TeleportService the same as the Teleport function. Try name your game:GetService(“Teleport Service”) something else but not Teleport. You can name it TeleportService

1 Like

If it worked it would be appreciated if you set it as solution so that it helps others as well

1 Like

@FunnelDeveloper I think you should mark my first post as the solution. This wasnt really a big problem, but I believe the first post I made in this topic has more to it.

1 Like