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

How can I find The player who clicked the Gui?

Asked by 10 years ago

I am making an FPS and am currently customizing the main menu and I have got a Script so far Ill add it at the End. Anyway I have the script Insert a Text button and make the Text change to loading... and I want to make It so that when it reads "Ready To Play" It will Delete itself from the specific PlayerGui Folder. Any Ideas? SCRIPT--

-- Create ScreenGui
local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent

-- Create TextButton
local textButton = Instance.new("TextButton")
textButton.Parent = screenGui
textButton.Position = UDim2.new(0, 25, 0, 50)
textButton.Size = UDim2.new(0, 150, 0, 50)
textButton.BackgroundColor3 = BrickColor.Black().Color
textButton.Text = "Click To Play!"

--[[Bind function to button click]]--
textButton.MouseButton1Down:connect(function()
    textButton.Text = "Loading..."
end)

wait(3)

textButton.Text = "Ready To Play!"

    if textButton.Text == "Ready To Play" then
         game.Players.user.PlayerGui.ScreenGui:Destroy()
        if game.Players.user.PlayerGui.ScreenGui:Destroy() == true then print("MainMenu Deleted")
                    end
                end
0
Why don't you clone the GUI into their playerGUI so it's unique to them? Mystdar 352 — 10y
0
Why don't you clone the GUI into their playerGUI so it's unique to them? Mystdar 352 — 10y
0
I'm just going out on a limb here -- is a surface GUI in play anywhere in this process? It doesn't sound like it, but as a helpful warning either way, you can't find who clicked a surface GUI. RoboFrog 400 — 10y

1 answer

Log in to vote
-3
Answered by 10 years ago

Okay, so, assuming this is a LocalScript, and assuming that the LocalScript is inside of the StarterGui, all you need to do is find the LocalScript's parent, and access the ScreenGui from there. So, you can use this edited version of your code:

-- Create ScreenGui
local player = script.Parent.Parent.Parent

local screenGui = Instance.new("ScreenGui")
screenGui.Parent = script.Parent

-- Create TextButton
local textButton = Instance.new("TextButton")
textButton.Parent = screenGui
textButton.Position = UDim2.new(0, 25, 0, 50)
textButton.Size = UDim2.new(0, 150, 0, 50)
textButton.BackgroundColor3 = BrickColor.Black().Color
textButton.Text = "Click To Play!"

--[[Bind function to button click]]--
textButton.MouseButton1Click:connect(function() --changed to click, otherwise they could click & hold

--ADDED THIS ALL INTO THE MOUSECLICK FUNCTION

textButton.Text = "Loading..."
wait(3)

textButton.Text = "Ready To Play!"

script.Parent.ScreenGui:Destroy()
print("Menu Deleted")

end)

0
The correct method for getting the player from a LocalScript is to do 'game.Players.LocalPlayer'. Perci1 4988 — 10y
0
Yes, that is correct, but I was showing him this simply for beginners' purposes. SlickPwner 534 — 10y
0
It's best to learn the correct method first. Perci1 4988 — 10y
Ad

Answer this question