Hi there! I was attempting on scripting a TextButton, witch when you click on it, you can buy a developer product or gamepass. Here’s the code that I’ve made but wasn’t working:
local button = script.Parent.TextButton -- The script is located inside the textbutton.
local productId = 123456789 -- Here goes the product ID (sample id displayed now)
local function purchaseProduct()
game:GetService("MarketplaceService").PromptProductPurchase(productId)
end
button.MouseButton1Click:Connect(purchaseProduct)
If someone could help me, it would be really useful, thanks!
local button = script.Parent.TextButton -- The script is located inside the textbutton.
local productId = 123456789 -- Here goes the product ID (sample id displayed now)
local function purchaseProduct()
game:GetService("MarketplaceService").PromptProductPurchase(game.Players.LocalPlayer,productId)
end
button.MouseButton1Click:Connect(purchaseProduct)
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local productId = 0000000 -- Change this to your developer product ID
-- Function to prompt purchase of the developer product
local function promptPurchase()
MarketplaceService:PromptProductPurchase(player, productId)
end
script.Parent.MouseButton1Click:Connect(promptPurchase())
Try this - it’s literally copy and pasted off the docs with a single line added to run promptPurchase() when the button is clicked.
Hello! And thanks for helping me out on this, I have been trying your script but the purchase appears when you join the game, instead of make the purchase when you click the buy button.
Hey! thanks you too for trying on helping me out! I’ve also tried your script and isn’t working, thanks anyways, if you have any other suggestions, tell me too!
I modified your code by a tiny bit. This should solve your problem:
local button = script.Parent
local productId = 123456789
local Market = game:GetService("MarketplaceService")
local Plr = game.Players.LocalPlayer
local function purchaseProduct()
Market:PromptProductPurchase(Plr,productId)
end
button.MouseButton1Click:Connect(purchaseProduct)