Duplicated button not working like the original?

(reposting because I posted on the wrong forum rip)

I currently have two buttons in a Surface GUI that teleport you to different games (think of it as a hub)

I labeled both buttons so you can see below:

image

The second button literally just doesn’t work. I have no idea why. I have gone through the code and nothing is any different other than the place IDs it is teleporting the player to.

To troubleshoot what the issue could have been, I literally copy and pasted the first button in place of the second. So they are identical in every way. It still does not work!

Anyone else experience this issue before, and if you have how did you manage to solve the issue?

TIA

4 Likes

Have you made it so the 2nd button is referencing things that are for the 2nd button only? And how does it not work? Is it unclickable? Does it not teleport you?

Any errors in Output? Errors when you click it?

Can you show some more stuff, like scripts and the explorer? Screenshots of two buttons and a description of what happened is not enough for us to help you.

1 Like

Yes let me elaborate.

Both buttons trigger the same event, however they pass different place IDs to teleport to.

I know the button is working, because it still triggers a GUI to appear telling the user they are being teleported (controlled by a separate script.)

However for some reason it seems the server isnt being told that the button is being pressed because TeleportService isnt being used for some reason.

I get absolutely 0 errors and no prints, unlike the first button.

Here is the code to each button. Like I stated before they are identical in every way except the place ID that is being carried over.

Button 1 (Localscript inside of button)

-- LocalScript inside TextButton
local button = script.Parent
local teleportService = game:GetService("TeleportService")
local player = game.Players.LocalPlayer

-- Print to debug
button.MouseButton1Click:Connect(function()
	print("Button clicked!")  -- Debug print statement
	local remoteEvent = game.ReplicatedStorage:FindFirstChild("TeleportRequest")
	if remoteEvent then
		remoteEvent:FireServer(18779044642) -- Replace with your target place ID
		print("Teleport request sent.")  -- Debug print statement
	else
		print("TeleportRequest RemoteEvent not found.")  -- Debug print statement
	end
end)

Button 2 (Localscript inside of button)

local button = script.Parent
local teleportService = game:GetService("TeleportService")
local player = game.Players.LocalPlayer

-- Print to debug
button.MouseButton1Click:Connect(function()
	print("Button clicked!")  -- Debug print statement
	local remoteEvent = game.ReplicatedStorage:FindFirstChild("TeleportRequest")
	if remoteEvent then
		remoteEvent:FireServer(129529971996782) -- Replace with your target place ID
		print("Teleport request sent.")  -- Debug print statement
	else
		print("TeleportRequest RemoteEvent not found.")  -- Debug print statement
	end
end)

Here is the Serverscript that fires when the remoteevent (teleport event) is fired.

local teleportService = game:GetService("TeleportService")
local replicatedStorage = game:GetService("ReplicatedStorage")

local teleportRequest = replicatedStorage:WaitForChild("TeleportRequestInteractive")

teleportRequest.OnServerEvent:Connect(function(player, targetPlaceId)
	print("Teleport request received for Place ID:", targetPlaceId)
	if player and targetPlaceId then
		teleportService:Teleport(targetPlaceId, player)
	else
		warn("Invalid player or Place ID.")
	end
end)

The first button works perfectly as expected, however the second button does not and gives no errors. Even when I am expecting it to tell me I cant teleport to another place in studio, which leads me to believe that the server for some reason is not being told that the player is trying to teleport

1 Like

So the 2nd button outputs:

“Button clicked!”
“Teleport request sent”
and
“Teleport request received for Place ID:” ?

I have something I want you to do. Can you put the Place ID for button 1 in button 2’s script and see if button 2 will display the teleport prompt now? If it prompts after you do that, then it’s something with that place’s configurations. If it still doesn’t work, let me know.

1 Like

Instead of duplicating the button with the script inside, just make a script that handles every button at once

1 Like

Yeah it still doesn’t work, which is why I’m so confused.

You are sure the button is clickable?

Yes, the GUI that tells you that you are teleporting shows when you click on the button. It just isnt telling the server the user is trying to teleport. Which is why im scratching my head wondering why it isnt working

I noticed this in the server script

local teleportRequest = replicatedStorage:WaitForChild("TeleportRequestInteractive")

but in the LocalScripts:

local teleportRequest = replicatedStorage:WaitForChild("TeleportRequest")

What’s the relationship between these two remoteEvents?

Fixed that issue, however the original problem still remains. the first button works and the second one doesn’t. They are identical in every way except the place ID. I even copied the first place ID and put it in the second localscript. Still does not work. This is becoming very frustrating because it literally makes zero sense why the second button is not working. :neutral_face:

Edit: I still am getting 0 errors. So the code is fine.

I also just added a print to go off when the event is fired to see if the second button is even firing the event, and for some reason it is not.

Figured out the issue everyone. Thanks for the help

What was the issue, if you don’t mind me asking?

yeah I loved the part when he did explain the issue

1 Like