Hello. I have been experiencing a very annoying issue with the MarketplaceService.
When I test my game, there is like a small chance when I buy my DeveloperProduct it will work.
Here is the local Script:
-- Replace with your GamePass ID
local gamePassId = 2682775305 -- Replace with your actual GamePass ID
-- Get the Player object
local player = game.Players.LocalPlayer
-- Get the button (assumes this script is inside the button)
local button = script.Parent
-- Function to prompt the Developer Product purchase
local function promptDeveloperProductPurchase()
-- Check if player exists
if player then
-- Prompt the player to purchase the Developer Product
print("Product bought from client!")
game.MarketplaceService:PromptProductPurchase(player, gamePassId)
else
warn("Player not found. Ensure this script is running in a LocalScript.")
end
end
-- Connect the function to the button's MouseButton1Click event
button.MouseButton1Click:Connect(promptDeveloperProductPurchase)
Here is the server script that processes the purchases:
-- Debug message at the start
print("Script running")
-- Ensure ProcessReceipt is set up every time
game.MarketplaceService.ProcessReceipt = function(receiptInfo)
-- Debugging: Confirm that the event is firing
print("ProcessReceipt triggered for ProductId:", receiptInfo.ProductId, "PlayerId:", receiptInfo.PlayerId)
-- Get the player who made the purchase
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
if player then
print("Player found: " .. player.Name)
-- Wait for the player's leaderboard data (or any other relevant data) to load
local leaderstats = player:WaitForChild("leaderstats", 10) -- Wait for leaderstats, with a 10-second timeout
-- Check if leaderboard data is available
if leaderstats then
print("Player's leaderboard loaded!")
-- Firing the event for the purchase
local success, errorMessage = pcall(function()
game.ReplicatedStorage.ProcessPurchase:Fire(player, receiptInfo.ProductId)
end)
if success then
print("Event fired successfully!")
else
print("Error firing event: " .. errorMessage)
end
else
-- Leaderboard not loaded
print("Player's leaderboard data not loaded in time.")
end
else
print("Player not found!")
end
end
Here is some videos of the problem:
Third party sales is on, HTTPS requests is on, The server script is in ServerScriptService, The local script is inside of a GUI button in StarterGui.
I use a M1 Macbook air for programming.