local MarketPlaceService = game:GetService"MarketPlaceService"
local function ownsgamepass(userid,gamepassid)
local s,res = pcall(MarketPlaceService.UserOwnsGamePassAsync,MarketPlaceService,userid,gamepassid)
if not s then
res = false
end
return res
end
If you actually take a look at the PlayerHasPass Wiki page, it says that the function has been deprecated, meaning that it’s no longer suitable for current works. This function have the parameters userId and assetId. It still works for Game Passes that have been created in the past, but not now.
In the other, the replacement is to use the UserOwnsGamePassAsync function. When using this function, the parameters will be userId and gamePassId. The gamepassId you can still retrieve it through the URL.
The link(s) above should have covered this for you but, UserOwnsGamePassAsync returns whether the player has bought a Game-pass or not
UserOwnsGamePassAsync returns true if the Player with the given UserId owns the game pass with the given game pass ID (not to be confused with asset ID).
Example:
local MarketPlaceService = game:GetService("MarketPlaceService ")
local PlayerBoughtThisGamePass = MarketPlaceService.UserOwnsGamePassAsync(Userid, GamePassiD)
if PlayerBoughtThisGamePass then
print("Player Has Bought This GamePass")
end
Put this script in ServerScriptService:
local GamePassID = --Gamepass ID
local MarketService = game:GetService(“MarketplaceService”)
game.Players.PlayerAdded:Connect(function(Plr)
local PlayerHasGamePass = MarketService:UserOwnsGamePassAsync(Plr.UserId, GamePassID)
if PlayerHasGamePass then
–Code
end
end)
local GamePassID = 'Gamepass code'
local MarketService = game:GetService(“MarketplaceService”)
game.Players.PlayerAdded:Connect(function(Plr)
local PlayerHasGamePass = MarketService:UserOwnsGamePassAsync(Plr.UserId, GamePassID)
if PlayerHasGamePass == true then
--code
elseif PlayerHasGamePass == false then
--code
end
end)
As I am pretty sure it would run the code if it successfully ran the Check and wouldn’t run if it returns true.
local GamePassID = 'Gamepass Code'--Gamepass ID
local MarketService = game:GetService(“MarketplaceService”)
local function CheckForGamepass(Plr)
local PlayerHasGamePass = MarketService:UserOwnsGamePassAsync(Plr.UserId, GamePassID)
if PlayerHasGamepass == true then
--code
elseif PlayerHasGamepass == false then
--code
end
end
game.Players.PlayerAdded:Connect(CheckForGamepass)