My gamepass product purchaser is not working?

Hi there.

I have recently been working on a game. I made a gamepass shop and unsurprisingly it did not work.

local market = game:GetService("MarketplaceService")
local plr = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
 if market:UserOwnsGamePassAsync(plr.UserId, 12886155) then
	market:PromptGamePassPurchase(plr.UserId, 12886155) 
 else	
	market:PromptGamePassPurchase(plr.UserId, 12886155) 
	market.PromptGamePassPurchaseFinished:Connect(function()
	  game:GetService("ReplicatedStorage").Carpet:FireServer()
	end)
 end
end) 

That is my code which is is a localscript. The gamepass is on sale and nothing seems to be wrong in the config but in game I get the error Unable to cast value to Object. When bought, it is meant to send a remote event but it is not even prompting!

Everything is fine in my explorer too.

What line is the error on?
Also i might be wrong on this but im pretty sure MarketplaceService and its functions can only be accessed by s Server Script

It can be accessed from local or server, the thing is, that he put if the user owns the gamepass it prompts it, and if they don’t on it, it gives them the item.

PromptGamepassPurchase has a player parameter, not player.UserId parameter.