--Thanks to @Sleazel for this script
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productId = 662920300
justOnce = true --set a debounce
function Shop(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then --only prompt players
local player = Players:GetPlayerFromCharacter(hit.Parent)
if justOnce then
justOnce = false
MarketplaceService:PromptProductPurchase(player, productId)
wait(1)
justOnce = false
end
end
end
script.Parent.Touched:connect(Shop)
--process player purchase in seperate function
ServerStorage = game:GetService("ServerStorage") --best place to keep unused items
local function processReceipt(receiptInfo)
-- this time find the player, by UserId of whoever made the purchase
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
-- The player probably left the game
-- If they come back, the callback will be called again
return Enum.ProductPurchaseDecision.NotProcessedYet
end
--IMPORTANT
if receiptInfo.ProductId == productId then
--insert code here that will give player whatever they just bought
print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)
end
--Instead of destroying the part, we move it to ServerStorage
--script.Parent.Parent = ServerStorage
--you can destroy it to if you want to, use
script.Parent:Destroy() --EDIT: Use this option for tycoon type game.
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt
I have a problem: The "window" with "Buy" and "Decline" the purchase, appear only the first time when people touch the part. If they click "Decline", they can't reopen the shop again.. same if people press "Buy", the part continues to remain in the world... I need create a "pleassure plate" where, when people touch it, they active the promptPurchase. If buy the DevProduct, the part disappear from the world or just remove
--Thanks to @Sleazel
--script.Parent.Parent = ServerStorage
--script.Parent:Destroy()
And if "Decline" the shop, it continues to stand in same position, waiting for someone to make the purchase and after someone buy, remove this part.
How i can fix it?
DevProductHandler
game.StarterGui.ResetPlayerGuiOnSpawn = true
local MarketplaceService = game:GetService("MarketplaceService")
function getPlayerFromId(id)
for i,v in pairs(game.Players:GetChildren()) do
if v.userId == id then
return v
end
end
return nil
end
MarketplaceService.ProcessReceipt = function(receiptInfo)
local productId = receiptInfo.ProductId
local playerId = receiptInfo.PlayerId
local player = getPlayerFromId(playerId)
local productName
if productId == 23408099 then
productName = "+$2,000"
local Money = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
if Money then
Money.Value = Money.Value + 2000
end
elseif productId == 23408103 then
productName = "+$10,000"
local Money = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
if Money then
Money.Value = Money.Value + 10000
end
elseif productId == 23407958 then
productName = "Day One $1,000!"
local cashmoney = game.ServerStorage.MoneyStorage:FindFirstChild(player.Name)
game.ReplicatedStorage.MasterKey:FireClient(player,"PurchaseConfirm")
if cashmoney then
cashmoney.Value = cashmoney.Value + 1000
end
elseif productId == 23408109 then
productName = "+5 Walkspeed"
local char = player.Character
if char then
local human = char:FindFirstChild("Humanoid")
if human then
human.WalkSpeed = human.WalkSpeed + 5
end
end
elseif productId == 671497722 then
productName = "Tappeto Volante"
game.ServerStorage.GoldenCarpet:Clone().Parent=player.Backpack
elseif productId == 662920300 then
productName = "Dropper"
game.ServerStorage.UltimDropper1:Clone().Parent=workspace
end
game.BadgeService:AwardBadge(playerId,202303025)
local message = Instance.new("Hint",workspace)
message.Text = player.Name.." purchased "..productName.."!"
coroutine.resume(coroutine.create(function()
wait(2)
message:destroy()
end))
return Enum.ProductPurchaseDecision.PurchaseGranted
end

4 comments
Okay I edited the script one more time. Silly mistake really. Please check my previous answer. I am not sure why the part is not being destroyed though.
Nope, not work, the problem is the same. Part not disappear. The problem can be because i use DevProductHandler in serverscriptservice?
yes i told you not to use multiple product receipt functions. You would need to destroy that part in that handler instead of what i just showed you.
And how i can edit DevProductHandler for a connect with the part? Edit the post