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

How to make a variable that accesses a player who has clicked on a GUI?

So technically I am trying to close a gui with a local script. But where the I have a problem is that, yes you can "Close it" after you reset, but I need it when they click the "X" button. So thats when accessing the player who clicked the gui comes in handy.

local frame = game.Players..PlayerGui.Starter.ScrollingFrame--Not sure how to find the player who clicked @ Players..PlayerGui?
function closed()
	frame.Visible = false
	print("Whats New/ Closed")
end
script.Parent.MouseButton1Down:connect(closed)

2 answers

✓ Accepted answer

Being a local script, this should be embedded in the player, meaning: EX: local plr = script.Parent.Parent.Parent (however many you need until you reach the Parent of PlayerGui) will get you the player that you want, Is that the answer you were looking for?

3 comments

0

omg.. Why didn't I think of that.. duhh.. thats man! :D

0

Yep no problem, sometimes the simplest solution is the one that works!

0

Ok someone who gave me the rep down PLEASE tell me why! I am so confused! I helped this person and my rep went DOWN 2 BECAUSE OF IT?

There is actually a read-only property of Players that can only be accessed from a local script called LocalPlayer.

You can use it in your script as so:

local player = game.Players.LocalPlayer
local frame = player.PlayerGui.Starter.ScrollingFrame

function closed()
	frame.Visible = false
	print("What's new/ Closed")
end
script.Parent.MouseButton1Down:connect(closed)

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