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

How do I get a player that clicked a GUI?

Asked by
P100D 590 Moderation Voter
10 years ago

My code looks like this:

01function opengui(click, click2)
02    print(click)
03    print(click2)
04    --local kiosk = script.Parent.Parent.Parent.Parent.Parent
05    --local shopgui = kiosk:FindFirstChild("ShopGui")
06    --local guiclone = shopgui:clone()
07    --guiclone.Parent = click.PlayerGui
08end
09 
10script.Parent.MouseButton1Down:connect(opengui)

click and click2 are both being printed out as numbers, that seem to be player position related. How do I get the player that clicked it, like I can with .Touched:connect?

0
Try using the localplayer, Because you're the one who clicks the button anyway. woodengop 1134 — 10y

1 answer

Log in to vote
4
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
10 years ago

Your parameters 'click' and 'click2' are being printed out as numbers because the MouseButton1Down event, the event you're using, returns two things;

  • The x coordinate that your mouse was on, on the gui.
  • The y coordinate

The event does not return the player that clicks.. so what you need to do is **make this a localscript ** and index LocalPlayer from game.Players.

1local plr = game.Players.LocalPlayer --The player
2 
3function opengui(click, click2)
4    local kiosk = script.Parent.Parent.Parent.Parent.Parent.ShopGui
5    shopgui:Clone().Parent = plr.PlayerGui
6end
7 
8script.Parent.MouseButton1Down:connect(opengui)
Ad

Answer this question