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

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

Asked by
Ulysies 50
8 years ago

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

Log in to vote
-2
Answered by 8 years ago

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?

0
omg.. Why didn't I think of that.. duhh.. thats man! :D Ulysies 50 — 8y
0
Yep no problem, sometimes the simplest solution is the one that works! adoScripting 0 — 8y
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? adoScripting 0 — 8y
Ad
Log in to vote
2
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

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)

Answer this question