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 4 years ago

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

07:57:29.741 - MarketplaceService:PromptProductPurchase() player should be of type Player, but is of type nil
07:57:29.743 - Stack Begin
07:57:29.744 - Script 'Workspace.Gifts.Display.SurfaceGui.Script1', Line 9
07: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:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local productID = 965613937

local function promptPurchase()
    local player = Players.LocalPlayer
    MarketplaceService:PromptProductPurchase(player, productID)
end

script.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 — 4y
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 — 4y
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 — 4y
0
I just realize your script work, so I change my answer. Check it now. Block_manvn 395 — 4y

2 answers

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

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

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local productID = 965613937

local function promptPurchase()
    local player = Players.LocalPlayer
    MarketplaceService:PromptProductPurchase(player, productID)
end

game.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 — 4y
Ad
Log in to vote
0
Answered by 4 years ago

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

Button.MouseButton1Click:Connect(function(promptPurchase)
    local MarketplaceService = game:GetService("MarketplaceService")
    local Players = game:GetService("Players")
    local productID = 965836984
    local player = Players.LocalPlayer
    MarketplaceService:PromptProductPurchase(player, productID)
end)

It works fine for me, tell me if it works

0
I'm still getting the same error. AzrefriskDreemurr 8 — 4y
0
If this is a normal script, use a local script instead, when your done please tell me if it worked! NathanTheCraziest 105 — 4y
0
Uh he can't. Because the script is in workspace. Block_manvn 395 — 4y
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 — 4y

Answer this question