This is my entire script. When I touch the block, nothing happens. It should print “You already have the pass”. I know it works because a separate player added event tells me that I own the pass. How can I fix this? script.Parent is a part. This is in a local script.
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local gamePassID = 26544839 -- 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 then
-- Player already owns the game pass; tell them somehow
print("You already have the pass")
else
-- Player does NOT own the game pass; prompt them to purchase
MarketplaceService:PromptGamePassPurchase(player, gamePassID)
end
end
script.Parent.Touched:Connect(promptPurchase)