Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

UserOwnsGamePassAsync is not working and there is no output?

Asked by
Galicate 106
6 years ago
Edited 6 years ago

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

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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
Ad

Answer this question