Help to make a gamepass donation system fetching the real gamepass creator id

Basically, when somewone purchase a gamepass i want the game to be able to know who bought it and who own the gamepass to send a message if the owner of gamepass is in game.

Difficulty:
image

Not same id found

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player,gamepass,bought)
	if not bought then
		return
	end
	
	-- Detect who donated to who with GetProductInfo
	local success,result = pcall(function()
		return MarketplaceService:GetProductInfo(gamepass)
	end)
	
	if not success then
		warn(result)
	end

	if success and not result then
		warn("No results found")
	end
	
	if success and result then
		local creator = result.Creator.Id
		local payer = player.UserId

		print(creator,payer)
	end
end)

Fixed with the following

local function CheckId(player,id,fetchtype)

	local Fetching = {
		Enum.InfoType.GamePass,
		Enum.InfoType.Product,
	}

	local function fetchid(id,ftype)
		local success,result = pcall(function()
			return MarketplaceService:GetProductInfo(id,ftype)
		end)

		if not success then
			warn(result)
			return
		end

		if success and not result then
			warn("No results found")
			return
		end

		if success and result then
			local creator = result.Creator.Id
			local payer = player.UserId
			local price = result.PriceInRobux

			local AssetOwner = game.Players:GetPlayerByUserId(creator)

			if not AssetOwner then
				print("Owner of asset not in game")
				print(result.Creator.Name)
				return
			end

			print(game.Players:GetPlayerByUserId(payer).Name.." donated "..price.. " to "..AssetOwner.Name)
		end
	end

	if fetchtype then
		fetchid(id,fetchtype)
		return
	end

	for _, fetch in Fetching do
		fetchid(id,fetch)
	end
end

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player,gamepass,bought)
	if not bought then
		return
	end

	CheckId(player,gamepass,Enum.InfoType.GamePass)
end)

MarketplaceService.PromptPurchaseFinished:Connect(function(player,product,bought)
	if not bought then
		return
	end

	CheckId(player,product,Enum.InfoType.Asset)
end)

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