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

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

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)

4 comments

0

Correction: I removed a comment in the code, so that error is meant to point to line 8.

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.

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

0

I just realize your script work, so I change my answer. Check it now.

2 answers

✓ Accepted answer

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.

1 comment

0

It works very well! Thank you!

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

4 comments

0

I'm still getting the same error.

0

If this is a normal script, use a local script instead, when your done please tell me if it worked!

0

Uh he can't. Because the script is in workspace.

0

The script is inside a part, and using a LocalScript doesn't do anything; I don't even get an error in Output.

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