Help with MarketplaceService

-- This script is supposed to prompt the purchase of the gamepass when
-- the player clicks on the imagebutton but it's not working

local mps = game:GetService("MarketplaceService")
local players = game:GetService("Players")
local plr = players.LocalPlayer
local pID = plr.UserId
local gpID = 13261240

script.Parent.MouseButton1Click:Connect(function()
	mps:PromptGamePassPurchase(gpID, pID)
end)

Error in output is:
Unable to cast value to Object - Client - LocalScript:8

This is my third time using MarketplaceService so i don’t know much about it.
Thanks!

mps:PromptGamePassPurchase(plr, gpID)
2 Likes

You want to prompt the game pass to the player, not the game pass ID. Also, using plr.UserId is unnecesary , you can just do

mps:PromptGamePassPurchase(plr,gpID)