I was testing the gamepass tutorial which is here: and I have realized that their script will always have haspass as false, is there a way to fix? I tested in studio and server within studio

Localscript:

-- This code should be within a 'LocalScript' object
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
 
local gamePassID = 5143841 -- Change this to your game pass ID
 
-- Function to prompt purchase of the game pass
local function promptPurchase()
 
	local player = Players.LocalPlayer
	local hasPass = false
 
	local success, message = pcall(function()
		hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID)
	end)
 
	if not success then
		warn("Error while checking if player has pass: " .. tostring(message))
		return
	end
 
	if hasPass == true then
		print(player.."already owns gamepass")
	else
		-- Player does NOT own the game pass; prompt them to purchase
		print(hasPass)
		MarketplaceService:PromptGamePassPurchase(player, gamePassID)
	end
end

script.Parent.MouseButton1Down:connect(promptPurchase)

Script::


local MarketplaceService = game:GetService("MarketplaceService")
 
local gamePassID = 5143841 -- Change this to your game pass ID
 
-- Function to handle a completed prompt and purchase
local function onPromptGamePassPurchaseFinished(player, purchasedPassID, purchaseSuccess)
 
	if purchaseSuccess == true and purchasedPassID == gamePassID then
		print(player.Name .. " purchased the game pass with ID " .. gamePassID)
		local Boombox = game.ServerStorage:FindFirstChild("BoomBox")
Boombox:Clone().Parent = player.Backpack
	end
end
 
-- Connect 'PromptGamePassPurchaseFinished' events to the 'onPromptGamePassPurchaseFinished()' function
MarketplaceService.PromptGamePassPurchaseFinished:Connect(onPromptGamePassPurchaseFinished)

Output: false , SilviaTheros911 purchased the game pass with ID 5143841 , false SilviaTheros911 purchased the game pass with ID 5143841 , false

2 comments

1

when testing it in studio you don't actually get the gamepass

0

Ty worked