You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want the dev product to be rewarded when the player buys the product on the spot. -
What is the issue? Include screenshots / videos if possible!
I have tested this code on a clean fresh plate and it works. However, when I place the code on another game (changing the dev product ID), it only works when the player rejoins the game after purchase. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
As mentioned above, it only worked in a clean place, but not on this other game.
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local nukeID = 1301147140
-- The core 'ProcessReceipt' callback function
local function processReceipt(receiptInfo)
print("process receipt")
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if not player then
print("fail")
return Enum.ProductPurchaseDecision.NotProcessedYet
end
task.spawn(function()
if receiptInfo.ProductId == nukeID then -- nuke code
-- active code goes here
end
end)
print("success")
return Enum.ProductPurchaseDecision.PurchaseGranted
end
-- Set the callback; this can only be done once by one script on the server!
MarketplaceService.ProcessReceipt = processReceipt
Basically, what I am looking for is why the code only runs when you purchase and rejoin.