I just wanted to know how to log when someone buys a third party asset through your game. Or is that even possible?
It is possible to log purchases to Discord through your game.
I’m not really sure how you can obtain a dev product ID for a third party asset, but here is a way to do it with your own products.
First of all, you need to create a discord webhook. You can learn how here.
Secondly, you must turn on HTTP Requests in your game. You may watch this tutorial.
Now in order to log players buying products in your games, you will also need your product’s ProductID. If you don’t have a dev product in your game yet or if you need to know how to obtain your dev product id, you can follow
this guide.
Now, here’s some code to log a message when a player buys a product in your game to Discord.
local MS = game:GetService("MarketplaceService") -- marketplace service for handling purchases
local Players = game:GetService("Players") -- needed to get players
local HTTPService = game:GetService("HttpService") -- service you use to send messages to disco
local proxy = "https://hooks.hyra.io" -- this is the proxy you should use, it ensures functionality and you dont get banned
local hook = "https://hooks.hyra.io/api/webhooks/WEBHOOK_CODE_HERE" -- replace https://discord.com/api/webhooks with https://hooks.hyra.io/api/webhooks/ before the code
hook = string.gsub(hook, "https://discord.com", proxy)
local productFunctions = {} -- table used to make functions for your dev products
productFunctions["DEV PRODUCT ID HERE"] = function(receipt, plr) -- replace DEV PRODUCT ID HERE with your dev product id
-- you may add your own code here
local d = HTTPService:JSONEncode({ -- the table for your message
["content"] = plr.Name.." bought ITEM for XXXX Robux. User ID: "..plr.UserId
-- this is what your webhook will say when this function is fired
-- replace ITEM with your dev product name and XXXX Robux with how much robux the product costs
-- this will also log the player id
})
HTTPService:PostAsync(hook, d)
end
MS.ProcessReceipt = function(receiptInfo) -- processing a player purchase (ONLY HAVE ONE PROCESSRECEIPT FUNCTION IN YOUR WHOLE GAME)
local userId = receiptInfo.PlayerId
local productId = receiptInfo.ProductId
local player = Players:GetPlayerByUserId(userId)
if player then -- checks if the player still exists in game
local handler = productFunctions[productId]
local success, result = pcall(handler, receiptInfo, player)
if success then
return Enum.ProductPurchaseDecision.PurchaseGranted
else
warn("Failed to process receipt:", receiptInfo, result)
end
end
return Enum.ProductPurchaseDecision.NotProcessedYet
end
This script uses MarketPlaceService and HttpService to help log a message when someone buys your product in Discord. MarketPlaceService is useful for all sorts of marketplace purchases, like gamepasses and dev products. HttpService is what allows your game to communicate with other websites. This script uses the POST method to send the message to Discord. It is very important you use the Hyra proxy as it is a proxy that complies with the Discord TOS and won’t get you banned on Roblox.
Hope this helps
Thank you for your help. But I need a script that detects when a gamepass/shirt is purchased through third-party products in our game.
And with the amount that was paid.
The MS.ProcessReceipt function works for gamepasses and shirts. Just add the gamepass/shirt id in a new ProductFunction like the one provided in the example.
ProcessReceipt does return the amount of Robux spent through a variable, so you can substitute that variable in the log message instead of manually typing it in.
Third party sales may also be recorded if you have Allow Third Party Sales turned on in your game. If you wish to turn them on, watch this tutorial, however enabling these can open up possible backdoors/scams from hackers. (like those games where they spam do you want to buy this shirt)
Again, I’m not sure on obtaining ProductIDs for third party assets, so it’s better to use your own products instead for more security.
We want to add this to a game with a server size of 1 player so I think hackers can’t spam other players that way.
The only possible way hackers could spam you with purchase dialogues is from viruses in free models. (models that are being sold for free in the toolbox) Just letting you know this could happen if you enable third party sales.
Also, don’t forget to mark your forum resolved.
Glad I was able to help.
Its simple use the marketplace services to detwcrt a purchase then marketplace server get product imfo creator if creator doesnt own game then its a third party sake (wrote on my phone)
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.