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
9 years ago

My code looks like this:

function opengui(click, click2)
    print(click)
    print(click2)
    --local kiosk = script.Parent.Parent.Parent.Parent.Parent
    --local shopgui = kiosk:FindFirstChild("ShopGui")
    --local guiclone = shopgui:clone()
    --guiclone.Parent = click.PlayerGui
end

script.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 — 9y

1 answer

Log in to vote
4
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 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.

local plr = game.Players.LocalPlayer --The player

function opengui(click, click2)
    local kiosk = script.Parent.Parent.Parent.Parent.Parent.ShopGui
    shopgui:Clone().Parent = plr.PlayerGui
end

script.Parent.MouseButton1Down:connect(opengui)
Ad

Answer this question