Getting error when clicking on a GUI to buy a gamepass

Hello, when I try to click a GUI in my game to buy a game pass the prompt does not show up and shows this error in the developer console:

The script is the following:

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

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

the script is written in a LocalScript.

Any fixes? Thanks in advance.

1 Like

Try this:

local player = game.Players.LocalPlayer

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

Nope, still getting the same error:

Are you sure you used the code? In my code there’s no variable at the second line

image

No more error but getting this popup instead, the game pass is still on sale tho

I believe I got this result on one of my old games. I think it is maybe an issue with your gamepass?

I have this script in a normal script in the Workspace which makes the game pass work. I’m not sure if there are any errors tho, gives me nothing in the output

local gamepassId = 37348329
local service = game:GetService("MarketplaceService")

game.Players.PlayerAdded:Connect(function(player)
	if (service:UserOwnsGamePassAsync(player.UserId, gamepassId)) then
		local tags = {
			{
				TagText = "chad",
				TagColor = Color3.fromRGB(74, 75, 69) 
			}
		}
		local ChatService = require(game:GetService("ServerScriptService"):WaitForChild("ChatServiceRunner").ChatService)
		local speaker = nil
		while speaker == nil do
			speaker = ChatService:GetSpeaker(player.Name)
			if speaker ~= nil then break end
			wait(0.01)
		end
		speaker:SetExtraData("Tags",tags)
		speaker:SetExtraData("ChatColor",Color3.fromRGB(0, 170, 255))
	end
end)

Maybe you should use PromptGamePassPurchase instead

local player = game.Players.LocalPlayer

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

Same error, should I try remaking the game pass and changing the id in both scripts?

Maybe, but check your gamepasses settings again. You probably missed something important. Or play the game instead of play testing in studio and see if it works

I’ve been receiving those errors in game, but after checking the script in studio it gives me some highlighted stuff and an error in the output, any clue on what could be causing this?

(just to clarify even if I put if (service:UserOwnsGamePassAsync(player.UserId, gamepassId)) then it still gives the same error)

There is nothing that defines what service and gamepassId are, hence the orange text. As for the red text, simply replace the if statement line with this:

if (service:UserOwnsGamePassAsync(player.UserId, gamepassId)) then

Edit: I see. I didn’t see your reply when I was typing this

1 Like

I think I’ve fixed it:

I simply specified at the top of the script

local gamepassId = 37348329
local service = game:GetService("MarketplaceService")

I’ve modified the first LocalScript with your script.

Thanks a lot for the help man!

1 Like