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

How do you check if a player has a gamepass?

Here's my script. The gamepass I'm using is a random one that I own. Why doesn't this work?

Gamepass: https://www.roblox.com/game-pass/7233611/Shadow-Raid-Pack

local GamepassID = 7233611

game:GetService("Players").PlayerAdded:Connect(function(player)
			
	if game:GetService("MarketplaceService"):PlayerOwnsAsset(player, GamepassID) then
		print("This player has the gamepass!")
	else
		print("This player doesn't have the gamepass!")
	end
							
end)

3 comments

0

Are you testing it in game or in the editor, because most of the time the editor doesnt have the ability to read that stuff.

0

I tried both and it doesn't work.

0

I found your problem "This method should not be used for game passes, since they use a separate ID system. Legacy game passes that still depend on an asset ID should use GamePassService:PlayerHasPass instead of this method."

2 answers

✓ Accepted answer

I found your problem "This method should not be used for game passes, since they use a separate ID system. Legacy game passes that still depend on an asset ID should use GamePassService:PlayerHasPass instead of this method." on PlayerOwnsAsset

So basically use UserOwnsGamePassAsync for new passes and PlayerHasPass for older legacy ones

There's a difference between a gamepass id and asset id. I would use this.

local gamepassID = 7233611

game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function()
	if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, gamepassID) then
	print("This player has the gamepass!")
else
	print("This player doesn't have the gamepass!")
	end
end)
end)

Hope this helps!

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