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.
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.
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!
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
.
-- 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
Its not broken, it's deprecated, you should be using :UserOwnsGamepassAsync instead.
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!