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.
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)
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)
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.
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)
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)
@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)
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.
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…
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.