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

Does GamePassService:PlayerHasPass not work properly in studio? Is it broken?

Asked by
Wiscript 622 Moderation Voter
5 years ago

Hi, I am trying to check if the player has a certain Gamepass using PlayerHasPass in a LocalScript .

I do this by invoking a server like so:

-- LocalScript in StarterCharacterScripts
local checkGamepass = game.ReplicatedStorage:WaitForChild("checkGamepass")
if checkGamepass:InvokeServer(123456) then
    print("True")
else
    print("False")
end
-- ServerScript in ServerScriptService
local checkGamepass = Instance.new("RemoteFunction",game.ReplicatedStorage)
checkGamepass.Name  = "checkGamepass"
checkGamepass.OnServerInvoke = function(player,id)
    if game:GetService("GamePassService"):PlayerHasPass(player,id) then
        return true
    end
    return false
end

For some reason, this doesn't work. In an actual game it always comes up with ´´false´´ (even though I do own the pass) and in Roblox Studio it just comes up with

"GamePassId '123456' is not of type Game Pass. Please use MarketplaceService:PlayerOwnsAsset instead."

Take in mind that the ID I used in this question isn't the actual ID for the gamepass. I just occulted it for privacy reasons. The real ID is a gamepass, however.

0
GamePassService is old InfiniteWhileLoop 19 — 5y

3 answers

Log in to vote
3
Answered by
green271 635 Moderation Voter
5 years ago
Edited 5 years ago

Gamepass Changes

A while ago, roblox changed how they handle gamepasses. They now have them as seperate assets. This casued a url change ("https://roblox.com/game-pass/id") aswell as the change in gamepass-fetching methods.

PlayerHasPass is broken and no longer in use. Instead, opt to use the new method UserOwnsGamePassAsync. The only thing that needs changing is your server script. Additonally, it now take's a players UserId, not the player object themselves.

IMPORTANT NOTE:

Using the gamepass ids you are currently using will not work. Instead, go to your inventory and click on the gamepass. Copy the id directly from the url, this is to ensure you are using the correct id!

Instance.new & Parenting

You should not be using the 2nd parameter of Instance.new. It is deprecated and should not be used in new work. Instead, set the parent using X.Parent = Y.

Solution

-- ServerScript in ServerScriptService
local checkGamepass = Instance.new("RemoteFunction")
checkGamepass.Parent = game.ReplicatedStorage
checkGamepass.Name  = "checkGamepass"
checkGamepass.OnServerInvoke = function(player,id)
    if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id) then
        return true
    end
    return false
end
0
The issue is NOT using the second parameter! https://devforum.roblox.com/t/psa-dont-use-instance-new-with-parent-argument/30296 The issue is setting a bunch of properties after parenting it, which he is not doing. User#22604 1 — 5y
0
Please reread my question before commenting, thanks. green271 635 — 5y
0
All green did was point out the second argument was deprecated. Nothing wrong about that. However the OnServerInvoke can be shortened to "return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, id)". UserOwnsGamePassAsync returns a boolean, so it would work. User#19524 175 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Its not broken, it's deprecated, you should be using :UserOwnsGamepassAsync instead.

1
in short do not use the GamePassService use the MarketPlaceService User#5423 17 — 5y
0
I've forgot to tell that. AswormeDorijan111 531 — 5y
0
the fact that it's deprecated isn't the most important part, it's the fact that it uses the old gamepass numbering system (see https://www.robloxdev.com/api-reference/function/GamePassService/PlayerHasPass) User#22604 1 — 5y
Log in to vote
0
Answered by
ABK2017 406 Moderation Voter
5 years ago

Yes gamepasses are no longer assets. You’ll want to update that part of your script using...

game:GetService('MarketplaceService'):UserOwnsGamePassAsync(player.UserId,        1234567)

Be sure that your GP ID hasn’t changed as well. Good luck!

Answer this question