MarketplaceService error

Error

MarketplaceService:PromptGamePassPurchase() player should be of type Player

Script (local)

local gamepassId = 92927931


script.Parent.MouseButton1Click:Connect(function(player)
	game:GetService("MarketplaceService"):PromptGamePassPurchase(player, gamepassId)

end)

@ii_inforcelaw
So you are getting the error because the “player” variable is not specified, youll need the UserId of the player to prompt the purchase them,
For Example:

game:GetService("MarketplaceService"):PromptGamePassPurchase(player.UserId, GamepassId)

If you are getting more errors, feel free to post here

i think MouseButton1Click doesnt return a player

I see what you mean when I try that it still does not work Ill take that info and Ill try to see if I can come up with something.

@ii_inforcelaw
So i have been testing and here is what i came up with:

local gamepassId = "your Id here"
local Plr = game:GetService("Players").LocalPlayer.UserId

script.Parent.Activated:Connect(function()
game:GetService("MarketplaceService"):PromptPurchase(Plr, gamepassId)
end)

Not exactly sure if it will work, but i think it does

Unable to cast value to Object - Error

Show the script in case you made an error or i did

1 Like

game:GetService("MarketplaceService"):PromptPurchase(Plr, gamepassId)

Try replacing the gamepassId Variable with the Gamepass Id

Same thing, It still shows that error

try making a variable that represents the MarketPlaceService

and then do MarketPlaceService:PromptGamePassPurchase(…

No, Same thing at this point I am not sure.

I now understand my mistake.

Here is the script that should work:

local Player = game:GetService("Players").LocalPlayer
local GamepassId = "Your Gamepass Id"

script.Parent.Activated:Connect(function()
game:GetService("MarketplaceService"):PromptPurchase(Player, GamepassId)
end)

The Error was that youre not supposed to have UserId, just LocalPlayer. That explains the casting error.

@ii_inforcelaw you had it right the first time, it was just the variable “player” didnt connect to the player, nor was it specified to the player. Sorry for my stupidity. :disappointed:

Yea, I think that`s the right fix for it.

1 Like

Yep it worked thanks. You helped alot!

But now they are saying its not for sale when its for sale?

check if the gamepass is for sale, if its for sale, try switching between :PromptGamePassPurchase

It works! Thanks for the answer!

1 Like