Enum.ProductPurchaseDecision.PurchaseGrante is always false?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

make the donate work

  1. What is the issue? Include screenshots / videos if possible!

Enum.ProductPurchaseDecision.PurchaseGrante is always false

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

i have try to make one but this is my first time so i do not know why is faild?

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local MarketplaceService = game:GetService("MarketplaceService")

local DonationDataStore = DataStoreService:GetDataStore("DonationData")
local DonationOrderedDataStore = DataStoreService:GetOrderedDataStore("DonationData")

local donateId = {1368761163, 1368761322, 1368761638, 1368761768, 1368762206, 1368762520}

function OnPromptProductPurchaseFinished(player, productId, purchaseResult)
	print(player, productId, purchaseResult)
	print('2', purchaseResult, purchaseResult == Enum.ProductPurchaseDecision.PurchaseGranted)
	if purchaseResult == Enum.ProductPurchaseDecision.PurchaseGranted then
		for i in donateId do
			if donateId[i] == productId then
				local success, currentAmount = pcall(function()
					return DonationDataStore:GetAsync(player.UserId)
				end)
				print('3')
				if not success then
					currentAmount = 0
				end
				print('4')
				currentAmount += purchaseResult.CurrencySpent
				DonationDataStore:SetAsync(player.UserId, currentAmount)
				DonationOrderedDataStore:SetAsync(player.UserId, currentAmount)
				print(player.Name .. " has donated " .. currentAmount .. " Robux.")
			end
		end
	end
end

MarketplaceService.PromptProductPurchaseFinished:Connect(OnPromptProductPurchaseFinished)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

ProductPurchaseDecision.PurchaseGranted is now referenced without the Enum prefix. Also, the corrected for-loop uses ipairs instead of in considering that donateId is an array, and the loop variable is named id instead of i.

The “in” keyword is used to iterate over tables, but donateId is an array, so you should use “ipairs” instead.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local DataStoreService = game:GetService("DataStoreService")
local MarketplaceService = game:GetService("MarketplaceService")

local DonationDataStore = DataStoreService:GetDataStore("DonationData")
local DonationOrderedDataStore = DataStoreService:GetOrderedDataStore("DonationData")

local donateId = {1368761163, 1368761322, 1368761638, 1368761768, 1368762206, 1368762520}

function OnPromptProductPurchaseFinished(player, productId, purchaseResult)
    print(player, productId, purchaseResult)
    print('2', purchaseResult, purchaseResult == ProductPurchaseDecision.PurchaseGranted)
    if purchaseResult == ProductPurchaseDecision.PurchaseGranted then
        for i, id in ipairs(donateId) do
            if id == productId then
                local success, currentAmount = pcall(function()
                    return DonationDataStore:GetAsync(player.UserId)
                end)
                print('3')
                if not success then
                    currentAmount = 0
                end
                print('4')
                currentAmount += purchaseResult.CurrencySpent
                DonationDataStore:SetAsync(player.UserId, currentAmount)
                DonationOrderedDataStore:SetAsync(player.UserId, currentAmount)
                print(player.Name .. " has donated " .. currentAmount .. " Robux.")
            end
        end
    end
end

MarketplaceService.PromptProductPurchaseFinished:Connect(OnPromptProductPurchaseFinished)

PromptPremiumPurchaseFinished seems to be missing documentation, but purchaseResult is actually a boolean dictating whether or not the player purchased the product. If true, the player purchased the product, if false, it wasn’t purchased.

Also on a sidenote it might be a good idea to switch over to .ProcessReceipt instead of .PromptProductPurchaseFinished as the former will allow the purchase to be retried if the relevant function errors, or if the purchase couldn’t be processed within 3(?) days, the player will be issued a refund.