How to make a gamepass prompt when clicking an imagebutton?

The title explains it, I have an ImageButton, and I want to make it clickable only if you own a gamepass, if you don’t own the gamepass, then clicking it will only make a gamepass prompt appear so that you purchase it, and after you purchase it you will be able to click the button. How do I make such a thing?

EDIT: Apologies as I also forgot to mention, the imagebutton opens another frame inside the same screengui, I want to make it so that if you don’t own the gamepass, it won’t open the frame and it will only show you the purchase prompt for the gamepass, but if you own the gamepass it wont show the prompt and it will open the frame and work normally.

1 Like

Did you already make the gamepass

1 Like

Yes! I created the gamepass for this feature, just gotta figure out a way to make it work.

Add a Local script inside of the Image button and Paste this Code

local Button = script.Parent
local Player = game.Players.LocalPlayer

Button.MouseButton1Click:Connect(function()
	game.MarketplaceService:PromptGamePassPurchase(Player, 323232) -- Change the 00 To the Id of your gamepass
end)
2 Likes

Don’t forget to change the 000 to your gamepass id.

1 Like

This is very simple, put a local script inside of your imagebutton and copy this:

script.Parent.MouseButton1Click:Connect(function(plr)
	local marketplace = game:GetService("MarketplaceService")
	local id = 00000000 --put your gamepass id here

	marketplace:PromptGamePassPurchase(game.Players.LocalPlayer.UserId,id)
end)
1 Like

sorry now i uderstand what you mean just wait and i will send a script

1 Like

Apologies as I also forgot to mention, the imagebuttons opens another frame inside the same screengui, I want to make it so that if you don’t own the gamepass, it won’t open the frame and it will only show you the purchase prompt for the gamepass, but if you own the gamepass it wont show the prompt and it will open the frame and work normally.

It does show the prompt but it shows for a pants from the avatar shop instead of the gamepass even though I put the correct ID of the gamepass.

Also I wrote something I forgot to mention in the last reply.

local marketplaceservice = game:GetService("MarketplaceService")
local id = 0000000 --replace with your gamepass id
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	if marketplaceservice:UserOwnsGamePassAsync(player.UserId,id) then
		print("player own gamepass")
		local frame = script.Parent.Parent --replace if the frame isnt there
		frame.Visible = not frame.Visible
	else
		marketplaceservice:PromptGamePassPurchase(player.UserId,id)
		print("player doesnt own gamepass")
	end
end)
1 Like

if that doesnt work try this:

local marketplaceservice = game:GetService("MarketplaceService")
local id = 0000000 --replace with your gamepass id
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:Connect(function()
	if marketplaceservice:UserOwnsGamePassAsync(player.UserId,id) then
		print("player own gamepass")
		local frame = script.Parent.Parent --replace if the frame isnt there
		if frame.Visible == false then
			frame.Visible = true
		else
			frame.Visible = false
		end
	else
		marketplaceservice:PromptGamePassPurchase(player.UserId,id)
		print("player doesnt own gamepass")
	end
end)
3 Likes

@Ghostinee Try this
Add a Local script inside of a the ImageButton with a Frame Inside of the ImageButton Named the Frame “BoughtFrame”

local MPS = game:GetService("MarketplaceService")
local Player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
	if MPS:UserOwnsGamePassAsync(Player.UserId,000) then -- replace 00 with gamepassid 
script.BoughtFrame.Visible = not script.BoughtFrame.Visible

else
MPS:PromptGamePassPurchase(Player.UserId,00) replace 00 with your id
end
end)
1 Like

This script is working very well! only issue is that it doesn’t show the gamepass prompt if you don’t own the gamepass

hmmm did you use the updated one?

1 Like

I don’t understand the part that says “replace 00 with your id”. If you don’t mind me asking, will it work only for me if I put my ID? Because I want this to work for anyone that joins the game.

Yes I did but for some reason the only thing that isn’t working in the script is showing the gamepass purchase prompt when clicking the button when you don’t own the gamepass.

try this instead

		marketplaceservice:PromptGamePassPurchase(player,id)
		print("player doesnt own gamepass")
1 Like

Add your gamepass id into the 000 Or else it will not show up.
It will work for everybody We can’t do your gamepass id Because we don’t Know it’s number…

1 Like

For more details to get it’s number go to the Gamepass Page on the Roblox website you will see a number in the Url.

1 Like

Yes I understand what you mean and I did put the correct gamepass ID, its just that it runs through the same issue that neon’s script goes through, it doesn’t show the prompt to purchase the gamepass.