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

Why won't this script trigger a purchase prompt?

So i've made a dialog through which a player can purchase a gamepass,however when i test it doesn't prompt the purchase or give any errors. This is basically the same script i use for other gamepasses which are activated via textbutton i only changed the way the function is connected but it doesn't work as i'd hoped.

Thanks for your time.

local marketplaceService = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local gamePassId = 687315880
local dialog = workspace.Representative1.Head.Dialog
local dialogY = dialog.DialogChoice2.Tip.DialogChoiceY
 
dialog.DialogChoiceSelected:connect(function(player,choice)
	if choice == dialogY then
  marketplaceService:PromptPurchase(player, gamePassId)
end)
 
local insertService = game:GetService("InsertService")
local Tip1 = game.ReplicatedStorage.Tip1
 
function onPurchaseFinished(player, assetId, isPurchased)
  if isPurchased and assetId == gamePassId then
    Tip1:Clone().Parent = player.Backpack
  end
end
marketplaceService.PromptPurchaseFinished:connect(onPurchaseFinished)
 

    player.CharacterAdded:Connect(function(character)
        if marketplaceService:PlayerOwnsAsset(player, gamePassId) then
			wait ()
            Tip1:Clone().Parent = player.Backpack
        end
    end)


1 answer

You forgot to end the if statement from line 8. Therefore, the script will error!

local marketplaceService = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local gamePassId = 687315880
local dialog = workspace.Representative1.Head.Dialog
local dialogY = dialog.DialogChoice2.Tip.DialogChoiceY

dialog.DialogChoiceSelected:connect(function(player,choice)
    if choice == dialogY then
       marketplaceService:PromptPurchase(player, gamePassId)
    end
end)

local insertService = game:GetService("InsertService")
local Tip1 = game.ReplicatedStorage.Tip1

function onPurchaseFinished(player, assetId, isPurchased)
  if isPurchased and assetId == gamePassId then
    Tip1:Clone().Parent = player.Backpack
  end
end
marketplaceService.PromptPurchaseFinished:connect(onPurchaseFinished)


    player.CharacterAdded:Connect(function(character)
        if marketplaceService:PlayerOwnsAsset(player, gamePassId) then
            wait ()
            Tip1:Clone().Parent = player.Backpack
        end
    end)

Any questions? Leave them in the comments! Thanks!

2 comments

0

while you were right that didn't solve my issue. The script doesn't fire at all so i get no errors

0

is it a local script or server script?

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