How to make transactions properly?

I’m wondering, does this look correct? And do I need to do this in a server sided script to avoid exploits, or does it not really matter since only the client will be activating this? Like I assume I need to do some sort of server sided check to see if they actually purchased the item? So do I need to do the ‘MarketplacePurchaseFinished’ event in a server script?

local button = script.Parent
local player = game.Players.LocalPlayer
local gamePassId = 0



button.MouseButton1Click:connect(function()
	if player then
		game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamePassId.Value)
	end
end)

game:GetService("MarketplaceService").MarketplacePurchaseFinished:Connect(function(player, productId)
	if productId == gamePassId then
		print("Success!")
	end
end)

Yes, your code looks correct for prompting a game pass purchase and handling the purchase in a client-sided script. However, as you mentioned, it is important to verify the purchase on the server to prevent exploits, such as using a third-party tool to spoof a purchase.

-- Client script
local button = script.Parent
local player = game.Players.LocalPlayer
local gamePassId = 0

button.MouseButton1Click:Connect(function()
if player then
game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamePassId.Value)
end
end)

-- Server script
game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
if player then
if receiptInfo.ProductId == gamePassId then
-- Grant the player access to the game pass
-- You could use a datastore to store the player's purchases
-- or grant access directly if the game pass is a one-time purchase
end
end
end

Sorry I did my best for the script

So I’m actually getting an error when trying to prompt the purchase with this script

https://gyazo.com/4b2ef83c27dac51c2afd5589f3e8508b

Any idea why? I tried testing it in studio, with a test server and on the real server all the same error.

It looks like the error message is indicating that there was an issue with the purchase process. Without more information, it’s difficult to say exactly what went wrong.

Try to verify that the Game Pass ID you are using is correct and exists on the Roblox Marketplace.

Verify that the player is logged in and has enough Robux to purchase the game pass.

Try testing the purchase process in another game or with another account to see if the problem persists.

https://gyazo.com/cac95dbfc2c86bc56461a74828bfefd7

I’ve confirmed all of that already.

local button = item1
local player = game.Players.LocalPlayer
local gamePassId = 1504961992

button.MouseButton1Click:connect(function()
	if player then
		print(player.Name, gamePassId) --> Prints matt1020304050, 1504961992
		game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamePassId)
	end
end)

The code looks correct and the gamePassId variable contains the correct id of your game pass.

It’s possible that the problem isn’t in the code, but rather in the Roblox account you’re using to test.

Like I said, I used 2 accounts to test. Same issue. I tried making a separate product id and still same issue.

Do you know how I can talk to some staff or something? I’ve looked through 20 posts now and all the issues they have I don’t have. This seems like some sort of internal error.

It seems like the error is occurring because item1 is nil or not defined. Make sure that item1 is defined and refers to the correct UI button. You can check this by printing item1 to the output console to see if it’s returning nil or the correct object.

I already did lol, there is no errors. It prints out both the player and the badge when the function is called.

According to the screenshot, you are trying to sell a developer product, not a game pass. You should be using MarketplaceService:PromptProductService() instead.

THANK YOU SIR! I didn’t even notice that.

BRO are you a ChatGPT bot or something? lol

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.