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
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.
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)
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.