Hello! I'm having trouble getting my Developer Product to grant the product, in this case 100000 Points. When I test it in Studio, I can click on my Surface Gui to bring my shop screen up, I click on the product, "Purchase 100000 Points", the screen pops up to confirm the purchase...but then the Points aren't added. I receive this error:
23:22:41.888 - userId is not a valid member of BoolValue
I'm not sure why my userId is not valid, I've seen the script laid out this way elsewhere.
Also, when I do a local server test, my Screen Gui won't appear at all when I click it, same for when I upload my game to Roblox itself and try. Any thoughts?
Here's my code below for the developer product:
local MarketplaceService = game:GetService('MarketplaceService') local devproductid = 48677962 -- DevId to Grant 100000 Points MarketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == devproductid then -- give them the Points player.leaderstats.Points.Value = player.leaderstats.Points.Value + 100000 end end end return Enum.ProductPurchaseDecision.PurchaseGranted end
And then I have this code inside the Text Button, inside the Frame, inside my Screen Gui inside Starter Gui:
local button = script.Parent local devproductid = 48677962 -- 100000 Points button.MouseButton1Click:connect(function() game:GetService('MarketplaceService'):PromptProductPurchase(game.Players.LocalPlayer, devproductid) end)
Thank you!
It sounds like you have a bool value located in the Players service for some reason. To fix this, you can use GetPlayers instead:
So change:
for i, player in ipairs(game.Players:GetChildren()) do
to
for i, player in ipairs(game.Players:GetPlayers()) do
That will make sure that you only get the players, and not anything else.
You can also simplify this even further by using GetPlayerByUserId:
local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId)
Final code:
local MarketplaceService = game:GetService('MarketplaceService') local devproductid = 48677962 -- DevId to Grant 100000 Points MarketplaceService.ProcessReceipt = function(receiptInfo) local player = game.Players:GetPlayerByUserId(receiptInfo.PlayerId) if player then if receiptInfo.ProductId == devproductid then -- give them the Points player.leaderstats.Points.Value = player.leaderstats.Points.Value + 100000 return Enum.ProductPurchaseDecision.PurchaseGranted end end return Enum.ProductPurchaseDecision.NotProcessedYet end