I have created a script that should prompt a gamepass to the player when clicked on through and image button but it doesn't seem to be doing that. Not sure what went wrong and I need some help.

local MarketplaceService = game:GetService("MarketplaceService")

local MainFrame = script.Parent.MainFrame
local janitorGamepass = MainFrame.JanitorGamepassFrame.JanitorGamepass
local OpenShop = MainFrame.Parent.OpenShop

local player = game.Players.LocalPlayer

local janitorGamepassID = 8861359

janitorGamepass.MouseButton1Down:Connect(function()
	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, janitorGamepassID)
end)
	
	if hasPass then
		print("player alread has the gamepass")
	else
		MarketplaceService:PromptGamePassPurchase(player, janitorGamepassID)
	end
end)

OpenShop.MouseButton1Down:Connect(function()
	MainFrame.Visible = not MainFrame.Visible
end)

3 comments

0

Are you getting any errors in the output?

0

Are you using a local script?, because if you aren't you can't define the player variable as that

0

Im not getting any errors but it just simply doesn't pop up. I am indeed using a localscript.