Gamepass purchase script "invalid"

Hi, Why7 is this invalid? I have the pass and all, but it will just come up with an invalid error.

local productId = 13992448 
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function() 
	game:GetService("MarketplaceService"):PromptPurchase(player, productId)
end)


Also, the text at the bottom is broken for no reason.

wait (5)
local Player = game.Players.LocalPlayer 
script.Parent.Text = Player.Name..", You own"
local gamePassID = 13992448  
local MarketplaceService = game:GetService("MarketplaceService")
local function onPlayerAdded(character)

	local player = game:GetService("Players"):GetPlayerFromCharacter(character)
	local hasPass = false


	-- Check if the player already owns the game pass
	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
	end)

	wait (7)
	if hasPass then
		coroutine.wrap(function()
			while true do
				wait (1)
				script.Parent.Text = "1 Out of 1 Gamepasses!" 
			end
		end)()
	else
		coroutine.wrap(function()
			while true do
				wait (1)
				script.Parent.Text = "0 Out of 1 Gamepasses!"
			end
		end)()
	end
end


onPlayerAdded(script.Parent)
1 Like

Your gamepass isn’t on sale right now

You might have to do PromptGamepassPurchase instead?


Still nothing.

Do you have API Services turned on?

You’ll have to setup a remote for the server to prompt the client instead.

Edit: Scrap that, the whole system seems fundamentally flawed. Let the server do 100% of the checking and prompting. When the prompt is successful, send the information back to the client that the purchase was successful, then change the text.

Crazy as it sounds, that made it work. Thanks for fixing it, and do you have a fix for this?

1 Like

Do that checking in the server as well.

--// Server //--
local MarketplaceService = game:GetService("MarketplaceService")
local gamePassID = 13992448
local CheckForGamepass = <RemoteFunctionDirectoryHere>

function CheckForGamepass.OnServerInvoke(player)
    local hasPass = false
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
    end)

    return hasPass
end

--// Client //--
local CheckForGamepass = <RemoteFunctionDirectoryHere>

-- somewhere in the client
if CheckForGamepass:InvokeServer() then
    --
end
1 Like