I have a few Developer products named Gold100, Gold500, Gold1000 and Gold2500 (inside a folder called which gives players cash. They are inside a folder called Gold, inside a folder called Gamepasses
I have a button which gets pressed and sends a remote event to the server. The server finds the remote event and then Prompts a Dev Product Purchase. When they buy it, They a function called ProcessReceipt will run and it will loop through a folder in ReplicatedStorage which has folders named after all the gamepasses.
Here's the problem: Everytime I make a purchase. It will loop again. For example if I pay for 2500 Gold once. It will give me 2500 Gold. If i pay for 2500 Gold twice, it will give me 2500 Gold, and then give me another 2500 Gold.
function ProcessReceipt(ReceiptInfo)
local Player = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)--Finds player
if Player then--if they exist
for i,v in pairs(ReplicatedStorage.Gamepasses.Gold:GetChildren())do
print("RECEIPT INFO PRODUCT ID =",ReceiptInfo.ProductId,"&","GOLD ID =",v.ProductId.Value)
if v.ProductId.Value == ReceiptInfo.ProductId then --If the product id matches the one the player bought
print("Found correct product id")
Player.Essentials.Currency.Gold.Value = Player.Essentials.Currency.Gold.Value + v.GoldPurchase.Value
--Player's Gold Value adds the amount of gold from the gamepass to the player
break--gets out of loop
end
end
print("went through all gold gamepasses")
end
end
RemoteEvents.C2S.Gamepass.Gold100.OnServerEvent:Connect(function(Player)--finds RE
local ProductID = GamepassFolder.Gold.Gold100.ProductId.Value --Gets Value of Product ID (This is a string value which stores the value of the developer product id_
MarketplaceService:PromptProductPurchase(Player,ProductID)--Prompts purchase
end)
RemoteEvents.C2S.Gamepass.Gold500.OnServerEvent:Connect(function(Player)
local ProductID = GamepassFolder.Gold.Gold500.ProductId.Value
MarketplaceService:PromptProductPurchase(Player,ProductID)
end)
RemoteEvents.C2S.Gamepass.Gold1000.OnServerEvent:Connect(function(Player)
local ProductID = GamepassFolder.Gold.Gold1000.ProductId.Value
MarketplaceService:PromptProductPurchase(Player,ProductID)
end)
RemoteEvents.C2S.Gamepass.Gold2500.OnServerEvent:Connect(function(Player)
local ProductID = GamepassFolder.Gold.Gold2500.ProductId.Value
MarketplaceService:PromptProductPurchase(Player,ProductID)
end)
MarketplaceService.ProcessReceipt = ProcessReceipt--Runs every time the player clicks buy
Would be nice if someone could help.

1 comment
Thanks!