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

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

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.

1 comment

0

GamePassService is old

3 answers

✓ Accepted answer

###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

3 comments

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.

0

Please reread my question before commenting, thanks.

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.

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

3 comments

1

in short do not use the GamePassService use the MarketPlaceService

0

I've forgot to tell that.

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)

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!

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