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

How to target the player that clicked?

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

✓ Accepted answer

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

8 comments

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).

0

There can be many local scripts. The Local Player is kind of omnipresent. It can be used for anyone in multiple scenarios.

0

And I got downed..

0

So if I put two LocalScripts in two different people, and then used a function to kill the LocalPlayer, who would die?

0

P.S. It wasn't me who downed you.

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.

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!

0

Yes, you are correct!

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).

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