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

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

Asked by 6 years ago

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

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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.

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. superdragonhunter64 2 — 6y
0
Not necessarily, because the event will fire when any gamepass is bought, I changed my answer so you can understand it more. SebbyTheGODKid 198 — 6y
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. superdragonhunter64 2 — 6y
0
You're welcome! Please accept this answer if it works. SebbyTheGODKid 198 — 6y
Ad

Answer this question