✓ Accepted answer
EDIT 2 : It is not my best day (see adjustments below). That should solve part not being responsive after declining a purchase. As for part not being destroyed, try script.Parent.Parent:Destroy() instead. It may be that the Parent of the script, is not the plate itself.
EDIT: Sorry I forgot to delete one line!
I did not fully understood Your intentions yesterday. To make a part disappear after a successful purchase, You need to do it inside Your ProcessReceipt function. You should have this function already implemented, make it so there. If not, and ONLY if not, please follow my instructions. DO NOT make multiple ProcessReceipt functions.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local productId = 662920300
justOnce = true
function Shop(hit)
if hit.Parent:FindFirstChild("HumanoidRootPart") then
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)
ServerStorage = game:GetService("ServerStorage")
local function processReceipt(receiptInfo)
local player = Players:GetPlayerByUserId(receiptInfo.PlayerId)
if not player then
return Enum.ProductPurchaseDecision.NotProcessedYet
end
if receiptInfo.ProductId == productId then
print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)
script.Parent:Destroy()
end
return Enum.ProductPurchaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = processReceipt
If you process the receipt elsewhere, please ignore this answer. If that is the case, you will need a different approach. Either finding the part in that other script or firing a BindableEvent. Have a nice scripting session.
3 comments
Do you want the part removed only after successful purchase, or regardless of player deciding to buy?
After successful purchase!
You dont really need to remove it you can just make it transparent and turn of can collide.