I am trying to work on this in my game, and when I buy the product it does not give me my credits.
local service = game:GetService("MarketplaceService") local player = game.Players.LocalPlayer local buyButton = script.Parent local productId = 23429504 buyButton.MouseButton1Click:connect(function() game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId) if service:PlayerOwnsAsset(game.Players.LocalPlayer, productId) then game.Players.LocalPlayer = game.Players.LocalPlayer + 10 end end)
In order for you to obtain anything from buying a Developer Product, you need to define the ProcessReceipt
of MarketPlaceService
.
Read more here
NOTE: The ProcessReceipt can only be defined in a server script(regular script) - attempting to define it in a localscript will cause it to not work.
Your script would error, to fix this figure out where the cash is. This is the server's side of the script.
function CompletePurchase() --This will error below, may need to know what you really want it to do. game.Players.LocalPlayer = game.Players.LocalPlayer + 10 end local MarketplaceService = Game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local productId = 23429504 MarketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == productId then CompletePurchase() end end end local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId ds:IncrementAsync(playerProductKey, 1) return Enum.ProductPurchaseDecision.PurchaseGranted end
Here's the player's side:
local buy = script.Parent local productId = 23429504 buy.MouseButton1Click:connect(function() game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId) end)
I will say that I don't know where the BuyButton is, so you'll have to change buy to where its at. The server's side goes in the model. The player's side goes in a local script in the StarterPack and possibly in the model in which that may make it even easier. Tell me if there's any errors.