Surface GUI Button Not Functioning

Hello, thanks for taking time to view this post.
I’ve recently been trying to set up a surface GUI button that on click sends you to a new place. I’ve been using this script:

script.Parent.MouseButton1Click:connect(function()

game:GetService("TeleportService"):Teleport("The Place ID")

end)

The button functions when it is a screen GUI, but when it’s a surface GUI the button does not function. Does anyone know how I can fix this?

Thank you for your help!

:connect is deprecated, it is now :Connect and also there shouldn’t be speech marks around the place’s ID

Hmm… It still didn’t work, I wonder if it’s just a bug.

Hmm… It still didn’t work, I wonder if it’s just a bug. Thanks anyway.

Oh yeah, you need to define the player and pass it on in the arguments.

game:GetService("TeleportService"):Teleport(placeid, player)

I’m very bad at scripting, sorry if this question makes me sound stupid, but what do I put for player? Would StarterPlayer work? I want the player who hit the button to be teleported.

local player = game.Players.LocalPlayer

You need to set the Adornee property of the surface GUI to the part the ui is on, or the part that you desire the ui to go on

It can be assigned manually in studio, or you can do this:

surfaceGui.Adornee = part

Also, to teleport a player, the correct syntax is:

game:GetService("TeleportService"):Teleport(PLACE_ID_HERE)

If the script is running on the client, you wouldn’t need to pass the player as the 2nd argument as the client can only kick their own player

EDIT: And be sure to check your output for errors pertaining to the script

3 Likes