I want to make it so that when someone makes a purchase in my game, a chat message is automatically sent showing the name of the user who made the purchase, the name of the purchased item, and its price.
I need help understanding how I can script this feature in my game to run effectively
I have this code but it doesnt work:
local function sendMessage(player, itemName, price)
local message = string.format("%s ha comprado %s por %d Robux!", player.Name, itemName, price)
game:GetService("Chat"):Chat(game.Players, message)
end
game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
if player then
local product = game:GetService("MarketplaceService"):GetProductInfo(receiptInfo.ProductId)
if product then
local itemName = product.Name
local price = receiptInfo.CurrencySpent
sendMessage(player, itemName, price)
end
end
end
If someone would be so kind to help me with the script I would be very grateful!
--game.ServerScriptService.Script:
local RS = game:GetService("ReplicatedStorage")
local event = Instance.new("RemoteEvent", RS)
--Fire this remote whenever you need to.
event:FireAllClients("username","purchaseName",50)
Client:
--game.StarterGui.LocalScript:
local StarterGui = game:GetService("StarterGui")
local RS = game:GetService("ReplicatedStorage")
local event = RS:WaitForChild("RemoteEvent")
event.OnClientEvent:Connect(function(playerName,gamepassName,gamepassPrice)
StarterGui:SetCore("ChatMakeSystemMessage", {
Text = playerName.." just purchased "..gamepassName.." for "..tostring(gamepassPrice).." robux!",
Color = Color3.fromRGB(255,255,255)
Font = Enum.Font.Arial
FontSize = Enum.FontSize.Size24
}
)
end)
Hey thanks for your help, but it didn’t work for me. It seems there was a mix up. I wanted to explain that my goal was that when someone buys an accessory for their avatar in my game (not a gamepass), the message will be shown, since my game is a place full of avatars for people to get inspired or copy the avatars. thank you anyway!