-
What do you want to achieve?
A working product. -
What is the issue?
-
What solutions have you tried so far?
Couldn’t find any post about this error.
This is the code in local script:
local MPS = game:GetService("MarketplaceService")
local plr = game:GetService("Players").LocalPlayer
local productId = 1737502343
script.Parent.MouseButton1Click:Connect(function()
local function promptPurchase()
MPS:PromptProductPurchase(plr, productId)
end
promptPurchase()
end)
This is the code in script found in server script service:
local SSS = game:GetService("ServerScriptService")
local dataManager = require(SSS:WaitForChild("Modules"):WaitForChild("DataManager"))
local MPS = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productFunctions = {}
--HERE
productFunctions[1737502343] = function(receipt, player)
local profile = dataManager.Profiles[player]
if not profile then return end
local fortune = player:WaitForChild("leaderstats").Fortune
profile.Data.Fortune += 100
fortune.Value = profile.Data.Fortune
return true
end
--HERE
-- Product ID 456456 awards 100 gold to the user
productFunctions[456456] = function(receipt, player)
local leaderstats = player:FindFirstChild("leaderstats")
local gold = leaderstats and leaderstats:FindFirstChild("Gold")
if gold then
gold.Value += 100
return true
end
end
local function processReceipt(receiptInfo)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then
-- Get the handler function associated with the developer product ID and attempt to run it
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
-- The user has received their benefits
-- Return "PurchaseGranted" to confirm the transaction
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
-- The user's benefits couldn't be awarded
-- Return "NotProcessedYet" to try again next time the user joins
return Enum.ProductPurchaseDecision.NotProcessedYet
end
-- Set the callback; this can only be done once by one server-side script
MPS.ProcessReceipt = processReceipt
I am completely new to making products or gamepasses and i have been following this to try and learn it: