Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

3 comments

0

LocalScripts have to be inside the Player or the Player's Character to function.

0

The MoustButton1Down event will not trigger when called from a Surface Gui, consider using a GuiButton or a ClickDetector

0

^ This is a correct answer.

2 answers

✓ Accepted answer

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. **

1 comment

0

well u basically just copied my answer.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.