Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I create an announcement from an ingame purchase?

I am setting up a monetization system in my game, with a shop gui and stuff, and I want to make it be announced when a player buys one of the items in the shop to the whole server through a text UI being created.

Basically its like this:

-Player buys product

-Announcement is displayed, "(Player) has bought (product)" for about 5 seconds

So far I just have the purchase prompt, so what do I add to it?

local devproduct = 1002728743 --Change id to devproduct
local player = game.Players.LocalPlayer
local service = game:GetService("MarketplaceService")

script.Parent.MouseButton1Down:Connect(function()
	service:PromptProductPurchase(player, 1002728743) -- Change id to devproduct
end)

1 answer

✓ Accepted answer
local MS = game:GetService("MarketplaceService")
b = nil
MS.ProcessReceipt = function(e)
	print("wwww")
	local b = e
	local suc,emsg = pcall(function()
		local e = b
local info = MS:GetProductInfo(e.ProductId,Enum.InfoType.Product)
local gui = Instance.new("ScreenGui",script)
gui.Name = "PlayerPurchase"
		local text = Instance.new("TextLabel",gui)
text.Text = game.Players:GetPlayerByUserId(e.PlayerId).Name .. " just bought " .. info.Name .. " for " .. info.PriceInRobux .. " Robux!"
		text.Size = UDim2.new(1,0,0.05,0)
		text.Font = Enum.Font.SourceSansLight
	text.BackgroundColor3 = Color3.new(1,1,1)
		text.BorderSizePixel = 0 
		text.TextScaled = true
local players = game.Players:GetChildren()
local guis = {}
for i = 1, #players do
local b = gui:Clone()
table.insert(guis,b)
b.Parent = players[i].PlayerGui
end
wait(5)
for i = 1, #guis do
guis[i]:Destroy()
		end
	end)
	if suc then
		return Enum.ProductPurchaseDecision.PurchaseGranted
	else
		warn(emsg)
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end

Remember: We help with scripting, we don't script your game.

Note: found out it doesn't work, fixing

Edit: fixed

1 comment

0

Note that this is a server script that you can put in ServerScriptService. Learn more about MarketplaceService.ProcessReceipt: https://developer.roblox.com/en-us/api-reference/callback/MarketplaceService/ProcessReceipt

This discussion is preserved as it was. New answers, comments, and votes are closed.