How do you check if a player owns a gamepass?

I am messing around with gamepasses, but when I tried something it didn’t work, how would I do this properly? I put it in a local script as well.

local GamepassID = 9427869
local Player = game.Players.LocalPlayer
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(Player, GamepassID) then
	print("Player owns gamepass.")
end
8 Likes

You would need to use the players UserId when checking if they own a game pass Id. Also I HIGHLY recommend to not put anything related to awarding players in the client side as you’re giving the client too much trust which could allow them to exploit this to award themselves whatever your game pass gives without actually having purchased it. I recommend if you want it to be when a player joins to have a Server Script that adds it on Players.PlayerAdded

5 Likes

Would I do

local GamepassID = 9427869
game.Players.PlayerAdded:Connect(function(player)
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserID, GamepassID) then
		print("Player owns gamepass.")
	end
end)
9 Likes

Yes, also It’s UserId. Check these for anything else which you may need.

Player

MarketplaceService

6 Likes