Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can I grant my Developer Product correctly?

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!

3 comments

0

Can you give us the line your error was on? Try capitalizing the first letter of 'userId' when you're getting a player's UserId. Also, sorry for what RomDino said, what he's doing is actually against the rules, and he has been reported.

0

It's okay, thank you for that. :) The answer from Foreverpower below allowed me to successfully make my purchase when I test it in Studio Play, but strangely, when I test the Local Server, or upload the game to Roblox, the Screen Gui with the Shop won't open. I get an error: 00:47:53.146 - PointsShop is not a valid member of PlayerGui PointsShop is my ScreenGui, which again works fine in Studio Pl

0

--Studio Play. Line 2 of the ScreenGui that it dislikes is: player.PlayerGui.PointsShop.ShopFrame.Visible = true Any thoughts? :(

1 answer

✓ Accepted answer

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

6 comments

0

Thank you!! That bit of code helped me successfully purchase the Points when testing the script in Studio Play Mode! :) But I still seem to have a problem making a purchase when I test the Local Server, or when i upload the game to the Roblox site. The error I receive appears to point to my Screen Gui, and won't even open the Screen Gui, which is odd, since it works just fine when I test it in S

0
  • in Studio. The error I receive is: 00:47:53.146 - PointsShop is not a valid member of PlayerGui PointsShop is my ScreenGui, which again works fine in Studio Play. Line 2 of the ScreenGui that it dislikes is: player.PlayerGui.PointsShop.ShopFrame.Visible = true
0

That's likely because it hasn't finished loading. Use WaitForChild to wait for it to load: http://wiki.roblox.com/index.php?title=API:Class/Instance/WaitForChild

0

Also, could you mark my answer as accepted if it worked for you?

0

Answer given! :) Thanks for the above answer, I tried using WaitForChild, but it still didn't seem to load properly. Its the strangest thing, I have the cursor icon to click the Screen Gui, but it doesn't actually click.

0

What is the code you are using for WaitForChild?

This discussion is preserved as it was. New answers, comments, and votes are closed.