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

How to get the player who clicked a TextButton?

Asked by 5 years ago

How would I get the Player who clicked the TextButton. The TextButton is in a surface GUI on a part in the workspace, so it is running off a Script, not a LocalScript.

local MarketplaceService = game:GetService("MarketplaceService")

local productID = 515812556

script.Parent.MouseButton1Click:Connect(function(Player)
print("working")
 if Player:GetRankInGroup(3563533) >= 30 then
  MarketplaceService:PromptProductPurchase(Player, productID)
 end
end)
0
The only thing I can think of would be to put a part in front of the button and place a click detector in it, then you can get the player when the player clicks the click detector. vissequ 105 — 5y
0
Just use a local script man. songboy50 77 — 5y
0
He can’t use localscript it’s in workspace vissequ 105 — 5y

3 answers

Log in to vote
2
Answered by 5 years ago

I believe that GUI's have a property called "Adornee". This means that you can put the GUI in the starter GUI and change the Adornee to the part that you're trying to display it on AND you can use local scripts. Correct me if I'm wrong and I'll take the answer down.

0
is there a way to do this with a billboard GUI? Rayguyban2 89 — 3y
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Unless you use a ClickDetector, there is no way the server is able to get who clicked the TextButton. Your best bet is to make it a Local Script that everyone has and pass the LocalPlayer in the parameters of the MarketPlaceService.

Last time I checked, MarketPlaceService still works on the client.

That way, it is able to trigger when the LocalPlayer presses the SurfaceGUI's TextButton and moreover prompt the LocalPlayer with a product.

Log in to vote
0
Answered by 5 years ago

So, change the button to a label, same settings, and put a click detector inside the part, and reference the click from the click detector. I don't think you could do it that way, it would also be a simpler way; maybe you could not 100% sure.

Ex:

Part Looks https://gyazo.com/a6975efa081bfaf81128ca62e4b19f1f

Part Hierarchy https://gyazo.com/7851f0a475707e70f30f16f01b4a6ca5

Script

local clicker = script.Parent.Click

local MarketplaceService = game:GetService("MarketplaceService")

local productID = 515812556



clicker.MouseClick:Connect(function(player)

if player:GetRankInGroup(3563533) <= 30 then

MarketplaceService:PromptProductPurchase(player, productID)

end

end)

Result https://gyazo.com/bc185498d3690bfb986e64e084bbb21a

Just added onto vissequ's comment and made it all and showed you, thanks to vissequ's comment and me elaborating onto it, you're code is now fixed.

Answer this question