TextButton teleporter not working

Heya! I am having trouble on scripting a textbutton, for being teleported to another experience (game), so I would like to solve the issue, is for my game UI. Here’s the script:

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("Inicio") --This is the ScreenGui name
local teleportButton = screenGui:WaitForChild("play") --That's the textbutton name


local function teleportToAnotherGame()

	local destinationPlaceId = 123456789 -- Sample universe ID for showing.


	local success, errorMessage = pcall(function()
		game:GetService("TeleportService"):TeleportToPlaceInstance(destinationPlaceId, "", player)
	end)


	if not success then
		warn("Teleportation failed: " .. errorMessage) --Error message for handle any issue.
	end
end

teleportButton.MouseButton1Click:Connect(teleportToAnotherGame)

Here’s an explorer screenshot:


“play” is the textbutton & “LocalScript” located inside is where I’ve made the script. If someone could help me to solve the issue, that would be great, thanks!

play is inside the frame, not inside the screengui

local teleportButton = screenGui:WaitForChild("Frame").play 

Well, I see also appart from the comment of location of the button, the script you sended, where should I place it or replace it exactly?

1 Like

replace it with the teleportButton variable

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("Inicio") 
local teleportButton = screenGui:WaitForChild("play") --replace this with the variable i provided
1 Like

Alright, so I’ve replaced as you said, and it’s still not working, here’s the actual code:

local player = game.Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
local screenGui = playerGui:WaitForChild("Inicio") 
local teleportButton = screenGui:WaitForChild("Frame").play


local function teleportToAnotherGame()

	local destinationPlaceId = 123456789 -- Sample universe ID for showing.


	local success, errorMessage = pcall(function()
		game:GetService("TeleportService"):TeleportToPlaceInstance(destinationPlaceId, "", player)
	end)


	if not success then
		warn("Teleportation failed: " .. errorMessage) --Error message for handle any issue.
	end
end

teleportButton.MouseButton1Click:Connect(teleportToAnotherGame)

If you have any other idea of what it’s making this fail, I’ll be glad to hear your suggestions or ideas. Console didn’t display any warning/error.