I want to prompt up a developer product purchase when a player clicks a block.
I already got the part of the purchase itself but I am not sure how to script the part with ClickDetector.
local sword = game.ServerStorage.Sword
local mpService = game:getService("MarketplaceService")
mpService.ProcessReceipt = function(purchaseInfo)
local plr = game:getService("Players"):GetPlayerByUserId(purchaseInfo.PlayerId)
if purchaseInfo.ProductId == 49078483 then
local Sword = sword:Clone()
Sword.Parent = plr.Backpack
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
This could have easily been solved by searching on the web, because I found this article that solves the problem, but all you simply need to do is use something called PromptProductPurchase(). You can add it in like this:
local productId = 0000000 -- id of dev product
local mps = game:GetService("MarketplaceService")
script.Parent.ClickDetector.MouseClick:Connect(function(player) -- grabs the player parameter
mps:PromptProductPurchase(player, productId) -- Prompts the purchase and makes sure to save it in the player
end)
Ok I am very sorry, when it comes to promptpurchase my brain goes stupid, it doesn’t matter which script you put it in, but in this case do a serverscript.
Scripting is one of my worst skills, and I’ve read alot of articles the Developer Hub. I still don’t understand it. Do I have to paste script 1 in the RemoteEvent in the ReplicatedStorage?
And do I have to put script 2 in a a LocalScript and put it in StarterPlayerScripts?
You made a small mistake in your code, you dont need to pass the UserId with the promptProductPurchase function. You need to pass the player itself.
local sword = game.ServerStorage.Sword
local mpService = game:getService("MarketplaceService")
script.Parent.ClickDetector.MouseClick:Connect(function(player)
mpService:PromptProductPurchase(player, 946322487)
end)
mpService.ProcessReceipt = function(purchaseInfo)
local plr = game:getService("Players"):GetPlayerByUserId(purchaseInfo.PlayerId)
if purchaseInfo.ProductId == 946322487 then
local Sword = sword:Clone()
Sword.Parent = plr.Backpack
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
If this helps, I have made a video on this for you @MeesBean (Also sent this to you in our little discussion). And this video can also be for anybody else who needs help on this: