Im new to using this ProcessReciept callback, and Im trying to make a main script with events to handle these purchases.
How do I disconnect an event one the purchase is handled? Im wondering this because whenever the purchase is prompt again it shows that it already is purchased, and fires the pushserverevent…
local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
local PushConnection = nil
MarketplaceService.ProcessReceipt = function(receiptInfo)
if PushConnection then
PushConnection:Disconnect()
PushConnection = nil
end
local PushConnection = ReplicatedStorage.Events.PushPurchaseEvent.OnServerEvent:Connect(function(PurchasePlayer, PurchasePlayer2, TargetPlayer)
if receiptInfo.ProductId == 1864776183 and receiptInfo.PlayerId == PurchasePlayer.UserId then
ReplicatedStorage.Events.PushServerEvent:Fire(TargetPlayer)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
end)
end