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

How to target the player that clicked?

Asked by
emite1000 335 Moderation Voter
10 years ago

When a player clicks a TextButton, it sets off a function, but how do I target the player who clicked that GUI button?

2 answers

Log in to vote
1
Answered by
Shawnyg 4330 Trusted Badge of Merit Snack Break Moderation Voter Community Moderator
10 years ago

You can use a local script to define the player as so: plr = game.players.LocalPlayer

0
But can't there be only one Local Script per a game because it makes the person that has it the LocalPlayer? (sorry if I'm wrong, I've never used them before). emite1000 335 — 10y
0
There can be many local scripts. The Local Player is kind of omnipresent. It can be used for anyone in multiple scenarios. Shawnyg 4330 — 10y
0
And I got downed.. Shawnyg 4330 — 10y
0
So if I put two LocalScripts in two different people, and then used a function to kill the LocalPlayer, who would die? emite1000 335 — 10y
View all comments (4 more)
0
P.S. It wasn't me who downed you. emite1000 335 — 10y
0
Well, you wouldn't need to parent the script to the player. You'd have it in Workspace or StarterGui. If you have a kill function in both of them, both will die. Think of it as just saying game.Players.shawnyg. Shawnyg 4330 — 10y
0
Oh, so when people have LocalScripts the game run each of them seperately for each person and targets the person playing? I think I get it now. Thanks! emite1000 335 — 10y
0
Yes, you are correct! Shawnyg 4330 — 10y
Ad
Log in to vote
-1
Answered by 10 years ago

Are you using a SurfaceGui? If so, parent the SurfaceGui to StarterGui, and make the Adornee the part you want it to be on (with a script inside the SurfaceGui). Then, using a LocalScript, detect when they click the button with MouseButton1Down (use a LocalScript because you can use Game.Players.LocalPlayer).

Answer this question