So i have been having some problems with my dev products. I have quite a few and plan to add more. For now it comes down to two things. I have a kill all button and a bunch of dev products that gives a currency within the game called Items.
The problem right now is that it’s looking like it doesn’t register when you purchase the product. The prompt works fine but it just doesn’t give items. It used to sometimes work and sometimes doesn’t.
I tried a bunch of fixes including trying to publish the game and even pay for the dev product within the game and it just does not work! I tried searching and even asking chatgpt. Hopefully someone has some ideas? At the moment i use both a server script and local script. Maybe not the best way but someone said it could be the issue.
Here’s The server script:
local ClickDetector = script.Parent
local productID = 2657161178 – Replace with your Developer Product ID
local itemAmount = 5 – The amount of items the player receives
– Services
local MarketplaceService = game:GetService(“MarketplaceService”)
local Players = game:GetService(“Players”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
– Wait for the RemoteEvent with a timeout period (5 seconds max wait)
local requestPurchaseEvent = ReplicatedStorage:WaitForChild(“RequestPurchase”, 5)
– If the RemoteEvent isn’t found, print a warning and stop the script.
if not requestPurchaseEvent then
warn(“RequestPurchase RemoteEvent not found in ReplicatedStorage!”)
return
end
– Function to handle purchase completion
local function onProductPurchased(player, productId, isPurchased)
if productId == productID and isPurchased then
print("Product purchased by " … player.Name)
-- Get the player's leaderstats
local leaderstats = player:FindFirstChild("leaderstats")
if leaderstats then
local itemsStat = leaderstats:FindFirstChild("Items")
if itemsStat then
print("Current Items Value: " .. itemsStat.Value)
-- Increase the "Items" leaderstat by the specified amount
itemsStat.Value = itemsStat.Value + itemAmount
print("Items granted. New Items Value: " .. itemsStat.Value)
else
print("Items stat not found!")
end
else
print("Leaderstats folder not found!")
end
else
print("Purchase failed or incorrect product ID")
end
end
– Handle the click event
ClickDetector.MouseClick:Connect(function(player)
– Send the request to the client to prompt for the purchase
requestPurchaseEvent:FireClient(player, productID)
end)
– Handle the purchase completion
MarketplaceService.ProcessReceipt = function(receiptInfo)
print(“ProcessReceipt triggered!”) – Debugging line
-- Print receiptInfo details for more context
print("Receipt Info: " .. tostring(receiptInfo.ProductId) .. " - " .. tostring(receiptInfo.PlayerId))
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if player then
-- Log player's name and receipt product ID for context
print("Player found: " .. player.Name)
-- Call the function to grant the items
onProductPurchased(player, receiptInfo.ProductId, true)
-- Return Purchase Granted status
return Enum.ProductPurchaseDecision.PurchaseGranted
else
-- If player not found, log this for debugging
print("Player not found: " .. tostring(receiptInfo.PlayerId))
end
-- If the receipt couldn't be processed, return not processed yet
return Enum.ProductPurchaseDecision.NotProcessedYet
end
And here’s the local script:
local MarketplaceService = game:GetService(“MarketplaceService”)
local ReplicatedStorage = game:GetService(“ReplicatedStorage”)
local requestPurchaseEvent = ReplicatedStorage:WaitForChild(“RequestPurchase”)
– Function to handle the purchase prompt
– Client-side script to handle the purchase prompt
requestPurchaseEvent.OnClientEvent:Connect(function(productID)
print("Prompting purchase for product ID: " … tostring(productID)) – Debugging line
MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer, productID)
end)