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

This Gui should work but it doesnt...?

Asked by
Ulysies 50
10 years ago

Im trying to make a Gui that you can click on and you can buy something. It is a regular script and a Textbutton inside a ScreenGui, inside the StarterGUI. The script is...

1local assetId = 27112438 --Insert any object Id
2 
3script.Parent.TextButton.MouseButton1Down:connect(function(player) --If true connect the function player
4Game:GetService("MarketplaceService"):PromptPurchase(player, assetId)
5end)

2 answers

Log in to vote
1
Answered by
2eggnog 981 Moderation Voter
10 years ago

The player is not passed as an argument when the MouseButton1Down event fires.

1local assetId = 27112438 --Insert any object Id
2 
3local player = script.Parent.Parent.Parent
4while not player:IsA("Player") do player = player.Parent end --Keep going up until we find the player
5 
6script.Parent.TextButton.MouseButton1Down:connect(function()
7game:GetService("MarketplaceService"):PromptPurchase(player, assetId)
8end)
0
Thank you now I will continue with my project! Ulysies 50 — 10y
Ad
Log in to vote
0
Answered by 10 years ago
1local bloxyColaId = 164625523--id of product or gamepass if its produt, its productid
2local player = game.Players.LocalPlayer
3 
4function onClick()
5Game:GetService("MarketplaceService"):PromptPurchase(player, bloxyColaId)
6end
7 
8script.Parent.MouseButton1Click:connect(onClick)
9--this goes in a local script

Answer this question