Echonet_11
(Echonet_11)
February 13, 2020, 8:01pm
1
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!
Vort3x_Z
(Vortex)
February 13, 2020, 8:03pm
2
:connect is deprecated, it is now :Connect and also there shouldn’t be speech marks around the place’s ID
Echonet_11
(Echonet_11)
February 13, 2020, 8:06pm
3
Hmm… It still didn’t work, I wonder if it’s just a bug.
Echonet_11
(Echonet_11)
February 13, 2020, 8:06pm
4
Hmm… It still didn’t work, I wonder if it’s just a bug. Thanks anyway.
Vort3x_Z
(Vortex)
February 13, 2020, 8:08pm
5
Oh yeah, you need to define the player and pass it on in the arguments.
game:GetService("TeleportService"):Teleport(placeid, player)
Echonet_11
(Echonet_11)
February 13, 2020, 8:11pm
6
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.
Vort3x_Z
(Vortex)
February 13, 2020, 8:12pm
7
local player = game.Players.LocalPlayer
Rare_tendo
(Rare_tendo)
February 13, 2020, 8:16pm
8
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