Error with By purchasing Gamepass

I want the player to be able to buy a gamepass for the core in my game

The thing is that when the player clicks on the button to buy a gamepass, an error appears

So far, no action has been taken to resolve this issue.

Here is the code that is used to try to purchase a gamepass (client script)

``


 local rem2 = game.ReplicatedStorage:WaitForChild("CoreTipi2") 
local marketplaceservice = game:GetService("MarketplaceService")
rem2.OnClientEvent:Connect(function(id)
    local player = game.Players.LocalPlayer    local success, message = pcall(function()
        marketplaceservice:PromptPurchase(player, id)    end)
        if not success then
        warn("Failed to prompt purchase: " .. message)        -- Optionally, notify the player of the failure
    end
end)
2 Likes

The code works, you didn’t specify the ID.

1 Like

The client receives a signal from Remote event And along with this signal, the gamepass ID is transmitted to the client.

1 Like

Is this script a local script? In that case, MarketPlaceService:PromptPurchase() is only available on the server side.

Bad error though, it should just tell you that you can’t do that on the client-side.

Change it to PromptGamePassPurchase.
You don’t need PromptPurchase.

 marketplaceservice:PromptGamePassPurchase(player, id) 

But you should use it on the server. I don’t recommend handling gamepass purchases in client scripts.

1 Like