Game Teleport Won't Work

  1. What do you want to achieve?
    I’d like to have the player teleported to a different game when they press the Textbutton within the ScreenGui

  2. What is the issue?
    It won’t work.

  3. What solutions have you tried so far?
    I’ve re-written the code multiple times but it still wont work.
    Also, I have ‘Allow 3rd Party Teleports’ On in Game Settings.

local teleportButton
local TeleportService = game:GetService("TeleportService")

function onTeleportButtonClicked()
	local placeId = 578872909 
	TeleportService:Teleport(placeId, game.Players.LocalPlayer)
end

-- This function is called when the button is clicked


teleportButton = script.Parent:FindFirstChild("TeleportButton")
if teleportButton then
	teleportButton.MouseButton1Click:Connect(onTeleportButtonClicked)
end

Screen Shot 2023-01-10 at 4.21.36 AM

teleportButton = script.Parent:FindFirstChild("TeleportButton")

In this line, you are just saying if LocalScript.Parent == TeleportButton.TeleportButton
You could just add another .Parent to the line or just keep it as script.Parent since you are going
through the Buttons Descendants instead.

So it could look like:

teleportButton = script.Parent

or

teleportButton = script.Parent.Parent:FindFirstChild("TeleportButton")
1 Like

I’ve changed the script to this:

local teleportButton
local TeleportService = game:GetService("TeleportService")

function onTeleportButtonClicked()
	local placeId = 578872909 -- Replace with the actual place ID of the destination game
	TeleportService:Teleport(placeId, game.Players.LocalPlayer)
end


-- This function is called when the button is clicked

-- Create the button and add it to the Surface GUI
teleportButton = script.Parent
if teleportButton then
	teleportButton.MouseButton1Click:Connect(onTeleportButtonClicked)
end

but it still won’t teleport the player

Is it server sided or locally sided?

If it’s only local, you are going to have to fire a remote event to get
the player teleported by the servers side.

1 Like

I tested her script locally yeah it works :+1:

1 Like

It’s a local script. The teleportation is to a different game created by me. I’m assuming it’d work since:

How should I go about firing a RemoteEvent to fix the issue?

It’s not guaranteed to work unfortunately :frowning_face: Only sometimes, that is why it is reccomended to use a server script.

1 Like

Thank you for testing it! I’m glad it works locally.

Should I just copy & paste the script into a Server Script instead within the SurfaceGUI?

You had the code right, but since it wasn’t done by the server it’s not going to send the player out to the other experience.

In replicated storage make sure to have a RemoteEvent of your own name, then, locally fire it so that that server can handle it afterwards.

game.ReplicatedStorage.RemoteNameHere:FireServer()

Then in a server script, within ServerScriptService area,

game.ReplicatedStorage.RemoteNameHere.OnServerEvent:Connect(function()
-- the rest of your teleportation code here (add the local values too, very important)
end)
1 Like

Is it because you are trying to teleport in Roblox Studio?
If so, you can’t.
Publish it then it should work in Roblox Player

No, it’s not that. I published the game and attempted to teleport in-game.

Just realised you are using a surfaceGui. LocalScripts don’t work in Workspace, I think. You would need to create a screenGui and insert the exact same gui and set the adornee property to the part you would like the telport button to be. Then, follow the steps from YourBossyLord.

steps:

Put your surfaceGui in your screengui, it can be in a folder called ‘surface gui’

image

Set adornee property to part face by clicking on it then the part you want it to be adorned on.

image

Then follow the other steps to do the teleport.

1 Like

Thank you for creating those steps! That is EXTREMELY helpful!

For my ServerScript, is this what it should look like?

game.ReplicatedStorage.GameTeleport.OnServerEvent:Connect(function()
	-- the rest of your teleportation code here (add the local values too, very important)
	local teleportButton
	local TeleportService = game:GetService("TeleportService")

	function onTeleportButtonClicked()
		local placeId = 578872909 -- Replace with the actual place ID of the destination game
		TeleportService:Teleport(placeId, game.Players.LocalPlayer)
	end

	teleportButton = script.Parent
	if teleportButton then
		teleportButton.MouseButton1Click:Connect(onTeleportButtonClicked)
	end

	game.ReplicatedStorage.GameTeleport:FireServer()
	
end)

But `onTeleportButtonClicked()’ is underlined in orange :confused:

Then my local script looks like this:

local teleportButton
local TeleportService = game:GetService("TeleportService")

function onTeleportButtonClicked()
	local placeId = 578872909 -- Replace with the actual place ID of the destination game
	TeleportService:Teleport(placeId, game.Players.LocalPlayer)
end


-- This function is called when the button is clicked

-- Create the button and add it to the Surface GUI
teleportButton = script.Parent
if teleportButton then
	teleportButton.MouseButton1Click:Connect(onTeleportButtonClicked)
end

game.ReplicatedStorage.GameTeleport:FireServer()

*GameTeleport is the RemoteEvent Name

Just follow this:

use your old localscript

local teleportButton
local TeleportService = game:GetService("TeleportService")

function onTeleportButtonClicked()
	local placeId = 578872909 -- Replace with the actual place ID of the destination game
	TeleportService:Teleport(placeId, game.Players.LocalPlayer)
end


-- This function is called when the button is clicked

-- Create the button and add it to the Surface GUI
teleportButton = script.Parent
if teleportButton then
	teleportButton.MouseButton1Click:Connect(onTeleportButtonClicked)
end
2 Likes

On your ServerScript, you have a line that fires the server, remove that. Also, you use game.Players.LocalPlayer to teleport the player in the ServerScript, but the server does not know who the local player is. You can fetch the plr value when the event is fired by doing this!

Local:



-- This function is called when the button is clicked

-- Create the button and add it to the Surface GUI
teleportButton = script.Parent
if teleportButton then
     teleportButton.MouseButton1Click.FireServer:Connect()
           game.ReplicatedStorage.GameTeleport:FireServer()
     end)

end

Server:

game.ReplicatedStorage.GameTeleport.OnServerEvent:Connect(function(plr) -- see plr here, that is how you fetch it
	-- the rest of your teleportation code here (add the local values too, very important)
	local TeleportService = game:GetService("TeleportService")

	
	local placeId = 578872909 -- Replace with the actual place ID of the destination game
	TeleportService:Teleport(placeId, plr) 
-- no need for function, can just do it
	
end)

EDIT: no need to fire server, i think @ProWJH said you can just teleport in local. Just use the same fixed local script with no fire server,

2 Likes

Send a RemoteEvent to the Server and teleport the Player from there.

Thank you so much! You’ve helped me learn many cool things :slight_smile:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.