Encountering errors while attempting to publish "games" in my game using MarketplaceService

Hello everyone! I’ve encountered an issue while using MarketplaceService in my game script. Specifically, when attempting to publish a game with the function MarketplaceService:PromptProductPurchase, I’m encountering an error that prevents successful transactions. The error message I receive states “Unknown error”, which suggests that the attempt to deduct Robux from the player is failing without a clear reason provided.

local function PublishGame(gameData)
	if gameData.Name and gameData.Description and gameData.IconId and gameData.ThumbnailId and gameData.GameId then
		local success, errorMsg = MarketplaceService:PromptProductPurchase(player, productID)
		if success then
			print("Published with 1000 Robux fee deducted!")
		else
			local errorMessage = errorMsg or "Unknown error"
			warn("Publish failed: " .. errorMessage)
			print("Error message:", errorMessage)
		end

		AddGame.GameName.GameName.Text = ""
		AddGame.Description.Description.Text = ""
		AddGame.IconID.IconID.Text = "" 
		AddGame.ThumbnailID.ThumbnailID.Text = ""
		AddGame.GameID.GameID.Text = "" 
	else
		warn("Cannot publish: All fields are required.")
	end
end

Screenshot 2024-07-10 225814

If someone could help out, that would be great. Thanks!
This is not the full script, but according to the error, it occurs here.

Your problem resides in this code right here:

I’m assuming you were trying to wrap this function inside of a pcall() in order to ensure everything works correctly. To correctly wrap it into a pcall function, you will want to call the PromptProductPurchase() within the pcall function and organize it like this:

local success, errorMsg = pcall(function()
	MarketplaceService:PromptProductPurchase(player, productID)
end)

That way your success variable is a boolean value which tells you whether the pcall() was successful or not and the errorMsg is whatever data is returned from the function (whether an error or whatever you told the function to return). There should also be no need for this line here:

The reason it would always show unknown error is because you only set the variable success to MarketplaceService:PromptProductPurchase(player, productID) and nothing was assigned to errorMsg

1 Like

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