Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

PromptPurchaseFinished example code from the WIKI isn't working. Am I missing something simple?

I'm using the example code from the PromptPurchaseFinished wiki page and I can't get it to function correctly. I feel like I may be missing something simple. I tried opening my active game from Studio and creating a new server script under ServerScriptService with the following code. When I step through it, nothing is printed. It just goes from line 5 to 11:

local MarketplaceService = game:GetService("MarketplaceService")
local assetId = 1241982351
local player = "SuperDragonHunter64"
local isPurchased = nil
MarketplaceService.PromptPurchaseFinished:connect(function(player, assetId, isPurchased)
	if isPurchased then
		print(player.Name .. " bought an item with AssetID: " .. assetId)
	else
		print(player.Name .. " didn't buy an item with AssetID: " .. assetId)
	end
end)

1 answer

✓ Accepted answer

Don't define player, isPurchased, or assetId. (Lines 02 - 04)

local MarketplaceService = game:GetService("MarketplaceService")
myId = 1337

MarketplaceService.PromptPurchaseFinished:connect(function(player, assetId, isPurchased)
	if assetId == myId then
 	   if isPurchased then
    	 	print(player.Name .. " bought an item with AssetID: " .. assetId)
   	 else
 	       print(player.Name .. " didn't buy an item with AssetID: " .. assetId)
  	 end
	else
		print("they didnt buy my id!")
	end
end)

Try that code instead.

4 comments

0

I tried that and it's the same result. Wouldn't it need those to be defined though? Especially assetId? Otherwise it wouldn't know what asset to check.

0

Not necessarily, because the event will fire when any gamepass is bought, I changed my answer so you can understand it more.

0

Ok, thank you. I understand now. The code you have listed does work. Once I make an in game purchase using PromptPurchase, the function you have above listens for any purchase made and returns the player, assetId, and if it was purchased.

0

You're welcome! Please accept this answer if it works.

This discussion is preserved as it was. New answers, comments, and votes are closed.