Why UserOwnsGamePassAsync isn't working

local Passlist = {
	VIP = {
		Id = 13600173502,
		givePass = function(Player)
			Player:SetAttribute("VIP", true) 
		end,
	},
}




game.Players.PlayerAdded:Connect(function(Player)
	Player:SetAttribute("VIP", false)
	
	
	local UserId = Player.UserId
	
	for _, Pass in pairs(Passlist) do
		if MarketplaceService:UserOwnsGamePassAsync(UserId, Pass.Id) then
			Pass.givePass(Player)
		end
	end
end)
3 Likes

Is there any error? And are you sure it’s a gamepass (I can’t find it)?

1 Like

And do you own the gamepass when you join the game?

1 Like

I have pass and no error
I don’t know why the script isn’t working

1 Like

You need to define the MarketplaceService variable as game:GetService("MarketplaceService").
Hence your script should look like this:

local Passlist = {
	VIP = {
		Id = 13600173502,
		givePass = function(Player)
			Player:SetAttribute("VIP", true) 
		end,
	},
}
local MarketplaceService = game:GetService("MarketplaceService")
game.Players.PlayerAdded:Connect(function(Player)
	Player:SetAttribute("VIP", false)
	
	
	local UserId = Player.UserId
	
	for _, Pass in pairs(Passlist) do
		if MarketplaceService:UserOwnsGamePassAsync(UserId, Pass.Id) then
			Pass.givePass(Player)
		end
	end
end)
1 Like

this is full script.

local MarketplaceService = game:GetService("MarketplaceService")
local BadgeService = game:GetService("BadgeService")
local CharacterFolder = workspace:WaitForChild("Characters")
local UsernameBilboard = script:WaitForChild("Username")

local Badgelist = {
	Wellcome = 1414222846680556,
}

local Passlist = { --툴일 경우에 이걸 스타터기어에 넣기
	VIP = {
		Id = 13600173502,
		givePass = function(Player)
			Player:SetAttribute("VIP", true) -- +체력은 200
		end,
	},
	
	
}




game.Players.PlayerAdded:Connect(function(Player)
	-- 에드리뷰트
	Player:SetAttribute("VIP", false)
	
	
	local UserId = Player.UserId
	-- 패스 지급
	for _, Pass in pairs(Passlist) do
		if MarketplaceService:UserOwnsGamePassAsync(UserId, Pass.Id) then
			Pass.givePass(Player)
		end
	end
	
	-- 환영배지
	BadgeService:AwardBadge(UserId, Badgelist.Wellcome)
	
	
	-- 캐릭터
	Player.CharacterAppearanceLoaded:Connect(function(Character)
		local Bilboard = UsernameBilboard:Clone()
		local DisplayName = Bilboard.DisplayName
		
		Bilboard.Parent = Character.Head
		Character.Parent = CharacterFolder
		
		if Player:GetAttribute("VIP") then
			
		end
	end)
	
	
end)

it’s Passlist.VIP since the gamepass id is contained there

He’s looping through Passlist. I suggest to use print() to debug and figure out if the script stops anywhere and if the script is being fully ran like how you want it to.

There are two IDs associated with gamepasses, the asset ID and the gamepass ID. The ID in your script doesn’t seem to link to an actual gamepass, so I believe you may have stored the asset ID instead of the gamepass ID. UserOwnsGamePassAsync expects the gamepass ID.

While on the configuration page of the gamepass, the URL will contain the actual gamepass ID that’s expected by UserOwnsGamePassAsync. Try using that instead of 13600173502.

1 Like

Is this a server script because you can only check if a player owns a gamepass in a server script. MarketplaceService doesn’t work on the client so must be called from the server.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.