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 6 years ago
Edited 6 years ago

this is my script

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

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 — 6y
0
The MoustButton1Down event will not trigger when called from a Surface Gui, consider using a GuiButton or a ClickDetector Le_Teapots 913 — 6y
0
^ This is a correct answer. xDestinoYT 2 — 6y

2 answers

Log in to vote
2
Answered by 6 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:

wait(1)
script.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)  ---

local tele = workspace.Teleports.SuperMan
local x = tele.Position.x
local y = tele.Position.y+5
local z = tele.Position.z
local player = game.Players.LocalPlayer -- Sets the localplayer

buttonnamelolidk.MouseButton1Down:connect(function() -- Put the full location of the button where buttonnamelolidk is
    player.Character.HumanoidRootPart.CFrame = CFrame.new(x,y,z) -- Teleports the player
end)

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 — 6y
Ad
Log in to vote
2
Answered by 6 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