I am currently working on a script that prompts the player with my developer product for a sword. When it is done, it is supposed to check if the purchase was a success and if so, give the player the sword. The player is prompted with the developer product purchase, but the function does not work to check. Nothing happens when I cancel and when I purchase. Any help is appreciated. Thanks!
Script:
--D00MED_S0ULL
local plr = game.Players.LocalPlayer
local Click = game.StarterGui.GUIClick
local gamepassId = 1207843619 -- All you have to do is change this to the right gamepass
local PromptCashPurchase = game.ReplicatedStorage.PromptCashPurhcase
local MarketplaceService = game:GetService("MarketplaceService")
local Sword = game.ReplicatedStorage.Tools.AzureSword
script.Parent.MouseButton1Click:Connect(function()
Click:Play()
MarketplaceService:PromptProductPurchase(plr, gamepassId)
MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, success)
if success then
if assetId == gamepassId then
local Clone = Sword:Clone()
Clone.Parent = player:WaitForChild("Backpack")
end
end
end)
end)
Success returns a bool value so you would check if its true or false:
local plr = game.Players.LocalPlayer
local Click = game.StarterGui.GUIClick
local gamepassId = 1207843619
local PromptCashPurchase = game.ReplicatedStorage.PromptCashPurhcase
local MarketplaceService = game:GetService("MarketplaceService")
local Sword = game.ReplicatedStorage.Tools.AzureSword
script.Parent.MouseButton1Click:Connect(function()
Click:Play()
MarketplaceService:PromptProductPurchase(plr, gamepassId)
MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, success)
if success == true then
if assetId == gamepassId then
local Clone = Sword:Clone()
Clone.Parent = player:WaitForChild("Backpack")
end
end
end)
end)
--D00MED_S0ULL
local plr = game.Players.LocalPlayer
local Click = game.StarterGui.GUIClick
local gamepassId = 1207843619 -- All you have to do is change this to the right gamepass
local PromptCashPurchase = game.ReplicatedStorage.PromptCashPurhcase
local MarketplaceService = game:GetService("MarketplaceService")
local Sword = game.ReplicatedStorage.Tools.AzureSword
script.Parent.MouseButton1Click:Connect(function()
Click:Play()
MarketplaceService:PromptProductPurchase(plr, gamepassId)
MarketplaceService.PromptPurchaseFinished:Connect(function(player, assetId, success)
if success then
local Clone = Sword:Clone()
Clone.Parent = player:WaitForChild("Backpack")
end
end)
end)
As it is a developer product, you must use ProcessReceipt as this tutorial indicates.
local script
local plr = game:GetService("Players").LocalPlayer
local Click = game:GetService("StarterGui").GUIClick
script.Parent.MouseButton1Click:Connect(function()
Click:Play()
game:GetService("MarketplaceService"):PromptProductPurchase(plr, 1207843619)
end)
script must be in ServerScriptService.
local PromptCashPurchase = game:GetService("ReplicatedStorage").PromptCashPurhcase
local Sword = game:GetService("ReplicatedStorage").Tools.AzureSword
local Functions = {}
Functions[1207843619] = function(receiptInfo)
local Player = game:GetService("Players"):GetPlayerByUserId(receiptInfo.PlayerId)
if not Player then return end
Sword:Clone().Parent = Player:WaitForChild("Backpack")
return true
end
game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
local Product = receiptInfo.ProductId
local Success, Completed = pcall(Functions[Product], receiptInfo)
if not Success or not Completed then
warn("Error:", Completed)
return Enum.ProductPurchaseDecision.NotProcessedYet
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
keep in mind if you add more products, they should all be as in table Functions and it should be like this