i would like to learn how to execute an action once a dev product is purchased, and would like to start something as simple as spawning parts into the workspace. i understand how the marketplace service is used, but i dont know where and how to proceed after that.
I have 2 questions:
- Do I have to write both scripts in order to make it work?
- Can I change the print line into the script I would like?
yes, the second script is local. it shows you how to create the prompt where it asks if the player wants to purchase the product.
the first script is on the server, and it runs everytime a product is purchased. you want to check the id, and if its the specific product that is supposed to create the parrts
local mkps = game:GetService("MarketplaceService")
local ProductId = 0
local function processReceipt(receiptInfo)
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
elseif player then
if receiptInfo.ProductId == ProductId then
-- add your code to create the parts here
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end
mkps.ProcessReceipt = processReceipt
see the comment i added? there you can add the part creation
make sure to change the product id’s in both scripts to the one you made
alright, thanks so much. I’ll try this out tomorrow and notify you on what errors I might occur
one more question, where do i put the local script to?
you can put it anywhere a local script works. player scripts folders, character, or starter gui. if you want a ui button to click then it shows the prompt, then put it in starter gui. otherwise i would put it in starterplayerscripts
so just copy paste the script into a local script in the starter gui as is? (because i have 4 buttons)
yes, but in the part of your code where you detect the ui being clicked, add this code
game:GetService("MarketPlaceService"):PromptProductPurchase(player, 0)
change the 0 to the product id
thanks for the help man, i managed to do the rest by myself following a video tutorial. i truly appreciate your effort in trying to solve my question
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.