Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

how do i get the player who clicked a button in a Surface GUI?

Asked by 7 years ago
Edited 7 years ago

this is my script

1local tele = workspace.Teleports.SuperMan
2local x = tele.Position.x
3local y = tele.Position.y+5
4local z = tele.Position.z
5script.Parent.MouseButton1Down:connect(function()
6    (Player Goes Here).HumanoidRootPart.CFrame = CFrame.new(x,y,z)
7end)

it is inside a surface gui and it doesn't work in a local script some reason

0
LocalScripts have to be inside the Player or the Player's Character to function. ee0w 458 — 7y
0
The MoustButton1Down event will not trigger when called from a Surface Gui, consider using a GuiButton or a ClickDetector Le_Teapots 913 — 7y
0
^ This is a correct answer. xDestinoYT 2 — 7y

2 answers

Log in to vote
2
Answered by 7 years ago

LOL. I also had this problem a while ago, anyway... Here's the answer (it is well-commented :D):

==================================

Make a localscript in the surface GUI (NOT IN THE BUTTON). Type the following in:

01wait(1)
02script.Parent.Adornee = -- FULL LOCATION OF THE PART WHERE YOU WANT THE BUTTON TO BE -- This just makes it so it will show up on the part (you will put the surface gui in starterGUI)  ---
03 
04local tele = workspace.Teleports.SuperMan
05local x = tele.Position.x
06local y = tele.Position.y+5
07local z = tele.Position.z
08local player = game.Players.LocalPlayer -- Sets the localplayer
09 
10buttonnamelolidk.MouseButton1Down:connect(function() -- Put the full location of the button where buttonnamelolidk is
11    player.Character.HumanoidRootPart.CFrame = CFrame.new(x,y,z) -- Teleports the player
12end)

Put the surface GUI in StarterGUI

** TIP: If the button still does not show, try rotating the part. **

0
well u basically just copied my answer. Benjamin_pro1000 3 — 7y
Ad
Log in to vote
2
Answered by 7 years ago

Try puting the SurfaceGui in the StarterGui and putting the SurfaceGui's Adornee to the part of where the surfacegui was before u put it in startgui

Answer this question