How to make developer purchase wait until function is complete

  1. What do you want to achieve?
    I want it so that when the player purchases a developer product, the local variable giftee calls the function gifteegrabber and then gets the player and gives them a gift.

  2. What is the issue? Include screenshots / videos if possible!
    It doesnt work always, it sometimes works flawlessly and sometimes just doesnt for whatever reason. It doesnt give an error message either so it is incredibly confusing to me.

  3. What solutions have you tried so far?
    I tried looking at the developer hub, turns out I am the only one with this issue.

Other details: the playerGUI is infact server sided so this isnt a client-server issue either.

I sincerely ask you for your help since this has plagued me since yesterday.

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local productFunctions = {}
function gifteegrabber(player)
	for i,v in pairs(player.PlayerGui.StageUI.HUD.Frames:GetChildren()) do
		if game.Players:FindFirstChild(v.Name) then 
			print(v.Name)
			return v.Name
		end
	end
end



productFunctions[00000] = function(receipt, player)
	local character = player.Character
	local humanoid = character and character:FindFirstChildWhichIsA("Humanoid")
	local giftee = game.Players[gifteegrabber(player)]

	
	giftee.Gifts.DoubleJump.Value = true
	player.PlayerGui.StageUI.HUD.Frames[giftee.Name]:Destroy()
	print("Successful!")
	return true
	
end
--I stole this from the roblox documentation >:)
local function processReceipt(receiptInfo)
	local userId = receiptInfo.PlayerId
	local productId = receiptInfo.ProductId

	local player = Players:GetPlayerByUserId(userId)
	if player then
		-- Get the handler function associated with the developer product ID and attempt to run it
		local handler = productFunctions[productId]
		local success, result = pcall(handler, receiptInfo, player)
		if success then
			-- The user has received their benefits
			-- Return "PurchaseGranted" to confirm the transaction
			return Enum.ProductPurchaseDecision.PurchaseGranted
		else
			warn("Failed to process receipt:", receiptInfo, result)
		end
	end

	-- The user's benefits couldn't be awarded
	-- Return "NotProcessedYet" to try again next time the user joins
	return Enum.ProductPurchaseDecision.NotProcessedYet
end

-- Set the callback; this can only be done once by one server-side script
MarketplaceService.ProcessReceipt = processReceipt

nevermind I fixed it, thank you Microsoft Copilot.

Turns out it didnt had any idea what to do incase no players existed.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.