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

how do i set a purchase completed prompt?

i have my game passes all set up but i want it so it prompts a success message after the purchase is complete

here's the prompt:

game.StarterGui:SetCore("SendNotification", {
    Title = "Purchase";
    Text = "Rejoin to receive your item!"
})

1 answer

I suggest using :PromptPurchaseFinished By using this you can identify if the player has bought the item or not. Then by following this code, you can make a message stating that they bought it, etc.

	local MarketplaceService = game:GetService("MarketplaceService")
	local Players = game:GetService("Players")
	local gamePassID = 5616721
	 
	function CheckPass(Player)
	 
	    local HasPass = false
	 

	    local Success, Message = pcall(function()
	        HasPass = MarketplaceService:UserOwnsGamePassAsync(Player.UserId, gamePassID)
	        print("Has Game Pass")
	    end)
	 

	    if not Success then
	        warn("Error while checking if player has pass: " .. tostring(Message))
	        return
	    end
	 
	    if HasPass == true then
		local Message = Instance.new("Hint",workspace)
		Message.Text = "Thanks for your purchase!"
		wait(5)
		Message:Destroy()
	    end
	end
	
	local function gamepassPurchaseFinished(player, gamepassId, isPurchased)
    	CheckPass(player)
	end

	MarketplaceService.PromptGamePassPurchaseFinished:Connect(gamepassPurchaseFinished)
	 
	game.Players.PlayerAdded:connect(function(Player)
	  Player.CharacterAdded:connect(function()
	    CheckPass(Player)
		MarketplaceService:PromptGamePassPurchase(Player, gamePassID)
		end)
	  end)

	Players.PlayerAdded:Connect(CheckPass)

I use this to check if the player owns the gamepass when joining or when done with PromptPurchase. You can also add Messages or Hints as I did. I hope you can use this or you learned something new! (:

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