So, I am making a script that when you buy a small pile of “bobux” it gives you ten. I made this script for it.
local MarketplaceService = game:GetService(“MarketplaceService”)
local function processReceipt(receiptInfo)
local player = game:GetService(“Players”):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
–player does not exist / left game
return Enum.ProductPurchaseDecision.NotProcessedYet
end
print(player.Name … "just bought " … receiptInfo.ProductId)
player.leaderstats.bobux.Value = player.leaderstats.bobux.Value + 10
Here is where the problem lies. I am also making a medium pile that gives you 75 bobux. How would I be able to recognize which one is being bought, and give the bobux accordingly.
local MarketplaceService = game:GetService(“MarketplaceService”)
local function processReceipt(receiptInfo)
local player = game:GetService(“Players”):GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
–player does not exist / left game
return Enum.ProductPurchaseDecision.NotProcessedYet
end
print(player.Name … "just bought " … receiptInfo.ProductId)
player.leaderstats.bobux.Value = player.leaderstats.bobux.Value + 75
ProcessReceipt passes the product Id to the function, whenever its called, just have a table that has the information about the Product Id, and then check how much reward you wanna give from it, for example like this:
local devProductRewards = {
[1249571274] = { Reward = 50 },
[2157128591] = { Reward = 100 }
}
local function processReceipt(receiptInfo)
local boughtProductInfo = devProductRewards[receiptInfo.ProductId] --This is where you get info from the table
print(boughtProductInfo.Reward) --Should print reward, if the id was found in the table.
end
MarketplaceService.ProcessReceipt = processReceipt
Also whenever you ask for code help, please format the code properly using ``` at top and end of code block
Don’t you mean like for suppose the player bought the developer product for 75 Bobux, which ID was for example: 124128571, and then you would want to give the reward according to the product Id.
And thats exactly what I gave the example for in my last post, above. You might want to read through what it does again
Okay, I don’t like to spoon feed but as this is seeming hard to you, I will do it and explain what I am doing.
So heres the example:
local devProductRewards = {
[1249571274] = { Reward = 50 }, --Here the 1249571274 is the key (just use product ID), which you access to get the Reward which is 50, so you can make an idea whats going in here I believe.
[2157128591] = { Reward = 100 } --Just like the above, this is same, except its for a different ID and reward.
}
local function processReceipt(receiptInfo)
local boughtProductInfo = devProductRewards[receiptInfo.ProductId] --This is where you get info from the table, using the product id as key as explained earlier
if not boughtProductInfo return end --Break the thread if product's info isn't found in the reward table
player.leaderstats.bobux.Value = player.leaderstats.bobux.Value + boughtProductInfo.Reward --This will get the Reward value from the table of the Key you got above
end
MarketplaceService.ProcessReceipt = processReceipt
If you are still having confusion with how the Table’s work and stuff, I highly recommend you try to learn them from the API reference. Also read comments through the code
Its alright, we’re always here at developer forum to help you out Also I would recommend you to learn more about the tables & stuff, as it seems you’re new to it