Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I'm trying to use the MarketPlaceService for developer products, and this is happening?

Asked by 5 years ago

When I attempt to run the code for prompting a developer product purchase I end up getting this in the output:

107:57:29.741 - MarketplaceService:PromptProductPurchase() player should be of type Player, but is of type nil
207:57:29.743 - Stack Begin
307:57:29.744 - Script 'Workspace.Gifts.Display.SurfaceGui.Script1', Line 9
407:57:29.745 - Stack End

I have no idea how to fix this and I have tried several things. Here's the code I'm trying to use as well:

01local MarketplaceService = game:GetService("MarketplaceService")
02local Players = game:GetService("Players")
03 
04local productID = 965613937
05 
06local function promptPurchase()
07    local player = Players.LocalPlayer
08    MarketplaceService:PromptProductPurchase(player, productID)
09end
10 
11script.Parent.Small.MouseButton1Click:Connect(promptPurchase)
0
Correction: I removed a comment in the code, so that error is meant to point to line 8. AzrefriskDreemurr 8 — 5y
0
Is this normal script, if yes then change it into Local one. Because the error said "player" should be Player instance but it nil. Block_manvn 395 — 5y
0
Or you can use PlayerAdded event to get the Player instance. And the comment above is wrong by the way :b https://developer.roblox.com/api-reference/event/Players/PlayerAdded Block_manvn 395 — 5y
0
I just realize your script work, so I change my answer. Check it now. Block_manvn 395 — 5y

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

EDIT: I just realize your script work, but it need some change:

01local MarketplaceService = game:GetService("MarketplaceService")
02local Players = game:GetService("Players")
03 
04local productID = 965613937
05 
06local function promptPurchase()
07    local player = Players.LocalPlayer
08    MarketplaceService:PromptProductPurchase(player, productID)
09end
10 
11game.Workspace.Gifts.Display.SurfaceGui.Small.MouseButton1Click:Connect(promptPurchase)

Change the script to LocalScript and put it in StarterPlayerScripts.

0
It works very well! Thank you! AzrefriskDreemurr 8 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

I already made a script... Why not you just try this:

1Button.MouseButton1Click:Connect(function(promptPurchase)
2    local MarketplaceService = game:GetService("MarketplaceService")
3    local Players = game:GetService("Players")
4    local productID = 965836984
5    local player = Players.LocalPlayer
6    MarketplaceService:PromptProductPurchase(player, productID)
7end)

It works fine for me, tell me if it works

0
I'm still getting the same error. AzrefriskDreemurr 8 — 5y
0
If this is a normal script, use a local script instead, when your done please tell me if it worked! NathanTheCraziest 105 — 5y
0
Uh he can't. Because the script is in workspace. Block_manvn 395 — 5y
0
The script is inside a part, and using a LocalScript doesn't do anything; I don't even get an error in Output. AzrefriskDreemurr 8 — 5y

Answer this question