I already have the button and the game will always be limited to 1 player per server if that helps any. I'm relatively new to scripting so I'm not sure how to do these types of things, plus I have a few other projects that could benefit from this knowledge.
Getting a player's GUI(s) when a button is clicked?
2 answers
A ClickDetector has the event MouseClick which passes the player who clicked it.
Example:-
Workspace.Part.ClickDetector.MouseClick:connect(function(playerWhoClicked)
-- "playerWhoClicked" would be game.Players.[playerWhoClicked]
-- so all we need to do is access the gui
local gui = playerWhoClicked:WaitForChild('PlayerGui')
-- we can now edit the players gui
-- You can use GetChildren() to get an array of all items in the players gui
end)
As you only have one player in the server then you will be able to make some assumptions so you would not need to "find" the gui as we know that there is only one player therefore:-
local plr = game.Players:GetChildren()[1] -- this must be the player
-- we should still use wait for child as things take time to load when a player joins the game for example
I hope this helps please comment if you do not understand how / why this script works.
Useful Links:-
Place a clickdetector in the block
function onClicked(playerWhoClicked)
player = game.Players:FindFirstChild(playerWhoClicked)
--from here you can create a variable for the players gui and do whatever with it
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
7 comments
Basically what I want is for when you click on a brick, it disappears and changes the text in the player's GUI but I know how to do that part, the only part I don't know is how to find the player that clicked so I can get to the player's GUIs.
Ah I see, i'll re-edit my post then
'player' is underlined in blue.
local player*, it'll still work. hover over it :)
Doesn't work, when I click on it this appears in the output: 07:24:45.558 - Workspace.MetalScrap1.Script:3: attempt to index local 'player' (a nil value)
A click detector passes the player object who clicked it, you do not need to find the player as you already have the player
As I said I'm relatively new to scripting so I don't know how to do that.
This discussion is preserved as it was. New answers, comments, and votes are closed.

3 comments
This worked for the most part but it takes two clicks for it to take effect on the GUI
Edit small typo
Nevermind it worked, thanks!