I've tried everything I could think of, but the function won't fire when I buy the dev product. sometimes after I rejoin the place, it recognises that I bought the item, but I'd like it to recognise instantly.
the place with the script in question is here
and here is the script in question, all variable references are to existing items
if game.ServerScriptService:FindFirstChild("VaporPurchaseHandler") ~= nil then script.Parent = game.ServerScriptService else script:Destroy() end -- debugging code added by ihaveamac enable_debug_print = true function print_d(m) if enable_debug_print then print("<debug> "..m) end end print_d("DEBUG MODE ACTIVE") local MarketplaceService = game:GetService("MarketplaceService") local PurchaseHistory = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local data = game:GetService("DataStoreService"):GetDataStore("VaporData") print_d("psready") MarketplaceService.ProcessReceipt = function(receiptInfo) print_d("purchased") local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId if PurchaseHistory:GetAsync(playerProductKey) then return Enum.ProductPurchaseDecision.PurchaseGranted end print_d("RUNNING: for i, player in ipairs(game.Players:GetPlayers()) do") for i, player in ipairs(game.Players:GetPlayers()) do print_d("RUNNING: if player.userId == receiptInfo.PlayerId then") if player.userId == receiptInfo.PlayerId then print_d("condition successful") local vapor = player.PlayerGui:FindFirstChild("Vapor") local props = vapor.Properties local GameId = props.ProductId.Value local suffix = props.DataSuffix.Value local main = vapor.Window if receiptInfo.ProductId == GameId then print(player.Name) print(main.Name) main.Buy.Visible = false main.Load.Visible = true print_d("gameIdAffirmative") if main.Buy:FindFirstChild("Gift") ~= nil and main.Buy:FindFirstChild("Gift").isGift.Value == true then print_d("isGift") local text = string.lower(main.Buy:FindFirstChild("Gift").GiftBox.Text) local giftlist = data:GetAsync("giftlist"..suffix) if giftlist ~= nil then local gifted = false for i = 1,#giftlist do if giftlist[i] == text then print_d("already gifted to "..text) gifted = true end end if gifted == false then print_d("gifted") table.insert(giftlist,text) data:SetAsync_d("giftlist"..suffix,giftlist) main.Load.Text.Text = "Gift Sent.." end end wait(1) main.Load.Text.Text = "Processing.." main.Load.Visible = false main:FindFirstChild("Buy").Visible = true elseif main.Buy:FindFirstChild("Gift").isGift.Value == false then print_d("notgift") data:SetAsync(player.userId..suffix,true) main.Load.Text.Text = "Purchase Complete.." wait(1) main.Load.Text.Text = "Processing.." wait(1) main.Load.Visible = false main.Buy.Visible = true main.Visible = false vapor.Back.Visible = false print_d("buydone") else print_d("notgift, and not notgift") end end else print_d("condition failed") end print_d("if statement completed") end PurchaseHistory:SetAsync(playerProductKey, true) print_d("purchasefinish") return Enum.ProductPurchaseDecision.PurchaseGranted end print_d("purchase handler is ready")
I would try using PromptPurchaseFinished it is a secondary way to solve the problem. http://wiki.roblox.com/index.php?title=API:Class/MarketplaceService/PromptPurchaseFinished