Hello! I would like make a money shop buyable with robux but I don’t know how to send an event when money is buyed. Could you help me please?
First, create a Remote and put it in ReplicatedStorage.
When the player buys the developer product, you can fire the remote using:
Remote:FireServer() -- Make sure to define "Remote" as your Remote Event object.
There are many different ways like :FireClient(), and :FireAllClients() but in your case I think you’ll be using FireServer().
To receive the fired event, you can go to the server and write:
Remote.OnServerEvent:Connect(function(plr) -- Same for here. Define "Remote" as the Remote Object you created.
-- do things
Also note that when firing a server event, the first parameter that is received from the remote is the player. You don’t have to put the plr as a parameter when firing, though, because it already gets it.
Additional Notes:
:FireServer() can only be fired from the client.
:FireClient() and :FireAllClients() can only be fired from the server.
I know already use remote events. I want just know how to detect when a developer product is buyed.
You use the ProcessReceipt
Callback to detect developer product purchases, for more information on how to make it work, for your needs
https://developer.roblox.com/en-us/api-reference/callback/MarketplaceService/ProcessReceipt
I don’t understant. Could you make a script please?
Of course, firstly, you already have the system in place for the prompting purchases?
Making a ProcessReceipt callback is simple, it’s basically just giving Processreceipt in MarketPlaceService a function for handling developer products. Here’s an example, palce the script in ServerScriptService
local mps = game:GetService("MarketplaceService")
local productfunctions = {}
productfunctions[12345] = function(receiptInfo,player) --Replace 12345 with your product id
player.leaderstats.Cash.Value += 10 --Adds 10 to the cash leaderstat, replace Cash with the name of your value
return true --We must return true for it to work
end
mps.ProcessReceipt = function(receiptInfo) --we get the info about the product
local plr = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not plr then --If the player left during purchase
return Enum.ProductPurchaseDecision.NotProcessedYet --Don't say it was granted
end
local handler = productfunctions[receiptInfo.ProductId] --Get the right function from our table
local success, result = pcall(handler,receiptInfo,plr) -- place it in a pcall so if it errors it wont break the script
if not success or not result then --A function was not found
warn("Error occurred while processing a product purchase")
print("\nProductId:", receiptInfo.ProductId)
print("\nPlayer:", player)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
return Enum.ProductPurchaseDecision.PurchaseGranted --Say the purchase was granted after the checks
end
You should have all the explanation in this script, make sure to replace values as you are told in the script