Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

UserOwnsGamePassAsync is not working and there is no output?

I tried gamepass service and marketplace service and NONE of them have worked at all. I get no error when using UserOwnsGamePassAsync and no output whatsoever. The only output is on line 2.

script.Parent.Parent.DialogChoiceSelected:Connect(function(player, choice)
	print("Selected to equip.")
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 4738167) and choice.Name == "Equip" then
		print("has glock")
        game.ServerStorage.Glock:Clone().Parent = player.Backpack
	end
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 4738176) and choice.Name == "Equip" then
		print("has card")
        game.ServerStorage["Level 1"]:Clone().Parent = player.Backpack
	end
end)

1 answer

My friend made a script for this purpose:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")

local gamePassID = 4444444  -- Change this to your game pass ID 
 
function onPlayerSpawned(player) 

    local hasPass = false
 
    -- Check if the player already owns the game pass
    local success, message = pcall(function()
        hasPass = MarketplaceService:UserOwnsGamePassAsync(player.userId, gamePassID)
        print("Has Game Pass")
    end)

    -- If there's an error, issue a warning and exit the function
    if not success then
        warn("Error while checking if player has pass: " .. tostring(message))
        return
    end
 
    if hasPass == true
-- Replace this with what you want to do if player owns gamepass
    end
end 

game.Players.PlayerAdded:connect(function(player)
  player.CharacterAdded:connect(function()
    onPlayerSpawned(player)
  end)
end)

-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerAdded:Connect(onPlayerSpawned)
--Script Created by Vissequ

This discussion is preserved as it was. New answers, comments, and votes are closed.