Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What does returning NotProcessed do when the player rejoins?

Asked by 4 years ago

I was wondering what returning NotProcessed does after a player purchases a developer product

I tested and purposly returned NotProcessed to see what happens in a game not a studio

my local script to prompt the purchase

script.Parent.TextButton.MouseButton1Down:Connect(function()
    game.MarketplaceService:PromptProductPurchase(game.Players.LocalPlayer, 666)
end)

the long server script

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


local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")

local productFunctions = {

[666] = function(receipt, player)
    if player.Character and player.Character:FindFirstChild("Humanoid") then
        -- Heal the player to full health
        player.Character.Humanoid.Health = 0
        -- Indicate a successful purchase
        return true
    end
end




}

-- The core 'ProcessReceipt' callback function
local function processReceipt(receiptInfo)
    -- Determine if the product was already granted by checking the data store  
    local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
    local purchased = false
    local success, errorMessage = pcall(function()
        purchased = purchaseHistoryStore:GetAsync(playerProductKey)
    end)
    -- If purchase was recorded, the product was already granted
    if success and purchased then
        print('Recorded')
        return Enum.ProductPurchaseDecision.PurchaseGranted
    elseif not success then
        error("Data store error:" .. errorMessage)
    end

    -- Find the player who made the purchase in the server
    local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
    if not player then
        -- The player probably left the game
        -- If they come back, the callback will be called again
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    -- Look up handler function from 'productFunctions' table above
    local handler = productFunctions[receiptInfo.ProductId]

    -- Call the handler function and catch any errors
    local success, result = pcall(handler, receiptInfo, player)
    if not success or not result then
        warn("Error occurred while processing a product purchase")
        print("\nProductId:", receiptInfo.ProductId)
        print("\nPlayer:", player)
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    -- Record transaction in data store so it isn't granted again
    local success, errorMessage = pcall(function()
        purchaseHistoryStore:SetAsync(playerProductKey, true)
    end)
    if not success then
        error("Cannot save purchase data: " .. errorMessage)
    end

    -- IMPORTANT: Tell Roblox that the game successfully handled the purchase
    print('Successfully Well Done')
    return Enum.ProductPurchaseDecision.PurchaseGranted
end

-- Set the callback; this can only be done once by one script on the server! 
MarketplaceService.ProcessReceipt = processReceipt

The problem is that whenever I rejoin it keeps erroring and printing things meaning it was not succesful

0
What line. iuclds 720 — 4y

Answer this question