I am having a problem with Skip stage dev product, It skips the stage fine but after the first purchase if you buy it again it will increase by two stages instead of one. Example: You are on stage 5 and skip to 6, if you try to skip from 6 to 7 you go to 8 instead and it increases by 1 so forth, how do I prevent this?
Button 4 purchase
local productId = 106153320 script.Parent.MouseButton1Click:connect(function() game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId) end)
ServerScriptService
local MarketplaceService = game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local productId = 106153320 MarketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == productId then player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1 player.Character.Humanoid.Health = 0 end end end local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId ds:IncrementAsync(playerProductKey, 0) return Enum.ProductPurchaseDecision.PurchaseGranted end
Try this:
local MarketplaceService = game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local productId = 106153320 MarketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == productId then player.leaderstats.Stage.Value = player.leaderstats.Stage.Value + 1 player.Character.Humanoid.Health = 0 local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.ProductId ds:IncrementAsync(playerProductKey, 0) return Enum.ProductPurchaseDecision.PurchaseGranted end end end Return Enum.ProductPurchaseDescision.NotProccessedYet end
I didn't test it, but that could be because you don't break the loop when you find the player. This way, only returns PurchaseGranted, if it was successful. Otherwise, it will return NotProccessedYet.