How to make a gamepass prompt when clicking an imagebutton?

YES! It worked perfectly thank you so so much!!!

(Do you mind editing the last code you posted and adding the line you wrote so that I add it as a solution)

or add a remote event in replicated storage and call it “PromptGamepass”
and change this inthe localscript in the button

game.ReplicatedStorage:WaitForChild("PromptGamepass"):FireServer(player)
		marketplaceservice:PromptGamePassPurchase(player,id)
		print("player doesnt own gamepass")

then add this right after else and add a script in serverscriptservice and copy this:

game.ReplicatedStorage:WaitForChild("PromptGamepass").OnClientevent:Connect(function(plr)
	local marketplace = game:GetService("MarketplaceService")
	local id = 0000000 --replace with gamepass id
	
	marketplace:PromptGamePassPurchase(plr.UserId,id)
end)
1 Like

oh nevermind then ingore the other one

1 Like
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,id)
		print("player doesnt own gamepass")
	end
end)
3 Likes

Sorry I made you go through all this trouble lol, thank you so much, and thank you to @lilmazen1234 too!

No problem, You’re welcome! Had fun doing it.

1 Like

You need to use pcall for network API methods as if they fail errors will occur.

1 Like

yes always use pcalls for anything currency related

1 Like