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

How can I find The player who clicked the Gui?

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

3 comments

0

Why don't you clone the GUI into their playerGUI so it's unique to them?

0

Why don't you clone the GUI into their playerGUI so it's unique to them?

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.

1 answer

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)

3 comments

0

The correct method for getting the player from a LocalScript is to do 'game.Players.LocalPlayer'.

0

Yes, that is correct, but I was showing him this simply for beginners' purposes.

0

It's best to learn the correct method first.

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