I am making a donation stand for an upcoming game of mine. I tested out the donation effects by using a bindable event to enable the particles when purchased, but the other button doesn’t fire the event and doesn’t enable the particles. Here is a video demonstrating it (If it loads):
Here is also the code to fire the event:
local ms = game:GetService("MarketplaceService")
local player = game:GetService("Players")
local bigid = 1556977734 --ID of big donation button
local smallid = 1556977147 --ID of small donation button
local event = game.ReplicatedStorage.DonationEvent --The event that enables the particles
ms.ProcessReceipt = function(r)
local player = player:GetPlayerByUserId(r.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if r.ProductId == bigid then
event:Fire()
print("Sending event")
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
ms.ProcessReceipt = function(r)
local player = player:GetPlayerByUserId(r.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if r.ProductId == smallid then
event:Fire()
print("Sending event")
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
this is probably due to ProcessReceipt already being set and when you set (it is like a property not a connection like a bindable event so you cant connect multiple functions) it again you either overwrite the previous function or it just doesn’t work.
Doing it the way you did it would also cause the code to be very long if you want more donations. A more efficient way of doing it would be to check the id and later do stuff based off the id using if, and and or
just a small note to this, it should be r.ProductId == smallid or r.ProductId == bigid then since otherwise it will only check if bigid is not nil, which will always return true since you’ve assigned it to a constant value (it doesn’t change)
A way to go about this if you’re going to add multiple ids is to use a table and table.find.
table.find will return nil if it doesn’t find the value in the table and will return its index if it does, knowing nil is basically equalled to false we can use this
local ids = {123, 456, 789}
if table.find(ids,tonumber(r.ProductId)) then
end
now if the product id is 123, 456 or 789 it will find the index and return a number, this will pass the if statement and continue inside the if. But if the product id is not found in the table if will return nil which is equalled to false and will stop the if statement