Click a block to prompt purchase

So this script (In a part) isnt working:

local plr = game.Players.LocalPlayer
local ID = 0 -- Random ID I put
script.Parent.MouseDetector.MouseClick:Connect(function()
game.MarketPlaceService:PromptGamePassPurchase(plr, ID
end)

for some reason it is not prompting.

You didn’t put ) after ID

Try this:

local plr = game.Players.LocalPlayer
local ID = 0 -- Random ID I put
script.Parent.MouseDetector.MouseClick:Connect(function()
game.MarketPlaceService:PromptGamePassPurchase(plr, ID)
end)
1 Like

Use a ServerScript (Normal Script) and do this:

local ID = 0
script.Parent.MouseDetector.MouseClick:Connect(function(plr)  --Adding plr after this specifies the player. 
game:GetService("MarketPlaceService"):PromptGamePassPurchase(plr, ID) -- I added :GetService() to it, and you also forgot the ) at the end. 
end)

If you need help, let me know. Thanks, WE

This is the full script, not working:
local plr = game.Players.LocalPlayer

local ID = 1121065450

script.Parent.ClickDetector.MouseClick:Connect(function()

game.MarketplaceService:PromptProductPurchase(plr, ID)

end)

ill check my output

So, I put a print after the mouseclick and it does not print. That is the issue…

Marketplace service after get service underlines, does not work at all

My bad, I mis-capped marketplace service. try this:

local ID = 0
script.Parent.MouseDetector.MouseClick:Connect(function(plr)  --Adding plr after this specifies the player. 
	game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, ID) -- I added :GetService() to it, and you also forgot the ) at the end. 
end)

And make sure its a ServerScript.

1 Like

It does not print what I told it to, I wanted a print after MouseClick. I think thats the issue.

local ID = 0
script.Parent.MouseDetector.MouseClick:Connect(function(plr)  --Adding plr after this specifies the player. 
	game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, ID) -- I added :GetService() to it, and you also forgot the ) at the end. 
print("Purchase Prompted. ")
end)

didnt print, its broken for some reason

I tested it, and it worked. I don’t know how to help. Perhaps this will work?
MarketplaceService (roblox.com)

So heres what to do, like I did it:
try this
Part in workspace
clickdetector and script in part.

Ok it worked but said something went wrong. You have not been charged…

Means you already own the gamepass.

1 Like

Its a dev product though…
Is promptdevproductpurchase a thing

Did you test this in the real game or roblox studio? If it is in roblox studio your account won’t be charged because it is a test purchase.

1 Like
local ID = 0
script.Parent.MouseDetector.MouseClick:Connect(function(plr)  --Adding plr after this specifies the player. 
	game:GetService("MarketplaceService"):PromptProductPurchase(plr, ID) -- I added :GetService() to it, and you also forgot the ) at the end. 
    print("Purchase Prompted. ")
end)

This is if you want it to prompt a Dev Product and not a gamepass like you say.

Okay so,

It isn’t prompting purchase because you didn’t put any product id in the ID variable. You also forgot to put ) after game.MarketPlaceService:PromptGamePassPurchase(plr, ID. So it should be game.MarketPlaceService:PromptGamePassPurchase(plr, ID).

You were not charged because you were in Roblox Studio. Roblox does this so you are able to test purchases without getting charged. In Roblox game client it will actually charge you. So don’t worry about that.

It’s better practice to use game:GetService() instead of game..

Yes, use Script and not LocalScript.


So here is the improved and fixed script.

local MarketplaceService = game:GetService("MarketplaceService") -- Get MarketplaceService
local Id = 1121065450 -- Your dev product id
local ClickDetector = script.Parent.MouseDetector -- Your click detector
ClickDetector.MouseClick:Connect(function(player) -- On click, get player and do the following below
	MarketplaceService:PromptProductPurchase(player, Id) -- Prompt the purchase, to the player with product id
end) -- End the function

Make sure that the Script is parented to the Part that contains MouseDetector object. Other than that happy scripting. If you have any questions, feel free to do so :wink:.