My code is meant to send a webhook message (Discord), but it doesn’t seem to work after I added multiple products, worked with one.
Any help? Here’s the code:
local MarketplaceService = game:GetService("MarketplaceService")
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local webhookLink = "dwdwdwd"
local embedColor = 4886754
-- Data store for tracking purchases that were successfully processed
local purchaseHistoryStore = DataStoreService:GetDataStore("PurchaseHistory")
-- Table setup containing product IDs and functions for handling purchases
local productFunctions = {}
-- 5 robux
productFunctions[940166911] = function(receipt, player)
local http = game:GetService("HttpService")
local data =
{
["embeds"] = {{
["title"] = "New Donation",
["thumbnail"] = {
["url"] = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&userId=" .. player.UserId,
},
["color"] = embedColor,
["fields"] = {
{
["name"] = "Robux Spent",
["value"] = receipt.CurrencySpent,
["inline"] = true
},
{
["name"] = "Username",
["value"] = player.Name,
["inline"] = true
}
},
["footer"] = {
["text"] = "Jees1#5825"
}
}
}}
data = http:JSONEncode(data)
http:PostAsync(webhookLink, data)
return true
end
-- 10 robux
productFunctions[940166869] = function(receipt, player)
local http = game:GetService("HttpService")
local data =
{
["embeds"] = {{
["title"] = "New Donation",
["thumbnail"] = {
["url"] = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&userId=" .. player.UserId,
},
["color"] = embedColor,
["fields"] = {
{
["name"] = "Robux Spent",
["value"] = receipt.CurrencySpent,
["inline"] = true
},
{
["name"] = "Username",
["value"] = player.Name,
["inline"] = true
}
},
["footer"] = {
["text"] = "Jees1#5825"
}
}
}}
data = http:JSONEncode(data)
http:PostAsync(webhookLink, data)
return true
end
-- 50 robux
productFunctions[940166943] = function(receipt, player)
local http = game:GetService("HttpService")
local data =
{
["embeds"] = {{
["title"] = "New Donation",
["thumbnail"] = {
["url"] = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&userId=" .. player.UserId,
},
["color"] = embedColor,
["fields"] = {
{
["name"] = "Robux Spent",
["value"] = receipt.CurrencySpent,
["inline"] = true
},
{
["name"] = "Username",
["value"] = player.Name,
["inline"] = true
}
},
["footer"] = {
["text"] = "Jees1#5825"
}
}
}}
data = http:JSONEncode(data)
http:PostAsync(webhookLink, data)
return true
end
-- 100 robux
productFunctions[940167003] = function(receipt, player)
local http = game:GetService("HttpService")
local data =
{
["embeds"] = {{
["title"] = "New Donation",
["thumbnail"] = {
["url"] = "http://www.roblox.com/Thumbs/Avatar.ashx?x=100&y=100&Format=Png&userId=" .. player.UserId,
},
["color"] = embedColor,
["fields"] = {
{
["name"] = "Robux Spent",
["value"] = receipt.CurrencySpent,
["inline"] = true
},
{
["name"] = "Username",
["value"] = player.Name,
["inline"] = true
}
},
["footer"] = {
["text"] = "Jees1#5825"
}
}
}}
data = http:JSONEncode(data)
http:PostAsync(webhookLink, data)
return true
end
local function processReceipt(receiptInfo)
local playerProductKey = receiptInfo.PlayerId .. "_" .. receiptInfo.PurchaseId
local purchased = false
local success, errorMessage = pcall(function()
purchased = purchaseHistoryStore:GetAsync(playerProductKey)
end)
if success and purchased then
return Enum.ProductPurchaseDecision.PurchaseGranted
elseif not success then
error("Data store error:" .. errorMessage)
end
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
local handler = productFunctions[receiptInfo.ProductId]
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
local success, errorMessage = pcall(function()
purchaseHistoryStore:SetAsync(playerProductKey, true)
end)
if not success then
error("Cannot save purchase data: " .. errorMessage)
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt
Any help is greatly appreciated, thanks!
P.S: I used the the DevHub Post code.