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

Finding You in ClickDetector?

Asked by
Tor6 0
10 years ago

I have created a button that when is clicked it opens your shop GUI. It works!; except the fact that every time the button is clicked (doesn't matter who) you're shop opens up. Is there a way to make it so that you're shop opens up only if the person that clicked the button is you?

3 answers

Log in to vote
0
Answered by
Savoron 15
10 years ago

When using a click detector the MouseClick event returns the player who click so:

Workspace.Part.ClickDetector.MouseClick:connect(function(playerWhoClicked)
  print("Part was clicked by: " .. playerWhoClicked.Name)
end)

Basically when doing this the playerWhoClicked you can get the player in game.Players or however you're opening to only open for the player that clicked. For more info on the click detector check out the wiki: Click Detector

0
thx for you're help!:D Tor6 0 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

The MouseClick event returns the player who clicked the ClickDetector. Script:

function onClick(player)
    player.Character.PlayerGui.ShopGui.Enabled = true
end

script.Parent.ClickDetector.MouseClick:connect(onClick(player))
0
thank you very much!:D Tor6 0 — 10y
Log in to vote
0
Answered by 10 years ago

Is it in a localscript?

0
yes Tor6 0 — 10y

Answer this question