Surface gui Button

I want to make a surface gui button that teleports player to another place.

That’s the photo of LocalScript’s location: Screenshot by Lightshot

And that’s the script:

local TeleportService = game:GetService("TeleportService")

local Place = 5598447761

local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()

TeleportService:Teleport(Place, player)

end)

What I have to do to make a surface gui button that teleports player to another place.

You only need place id, not the player, as this is a localscriptAlso, use :Connect() as :connect() is deprecated.

I did it but its not working. Its working on StarterGui but Im doing this on SurfaceGui.

Where is your script located?

(This won’t work if it’s parented to workspace, use a server script instead.)

That’s the photo of LocalScript’s location: Screenshot by Lightshot
Its:

game.Workspace.Part.SurfaceGui.TextButton.LocalScript

Localscripts don’t run in workspace (unless it’s parented to a player’s character, a tool etc etc.)

Use a server script.

In oder for Interactive UI elements to work, Such as Buttons. Put the SurfaceGui into StarteGui and change the Adornee property to the part u want the SurfaceGui to display on.

And it should be a LocalScript

2 Likes

Its not working on the Server Script too

You can’t just copy paste the localscript one.

You need a reference to the player, you also need to pass the player within the :Teleport() method as well the place id.

Thank you so much! Its now working.