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

[SOLVED] How do I properly check if a player has a gamepass, nothing I'm trying is working?

So I'm trying to make so when you have a gamepass in my game, you get your exp gain multiplied by 2. When I use

if passService:PlayerHasPass(player,5429209) then

end

it prints the error: GamePassId '5429209' is not of type Game Pass. Please use MarketplaceService:PlayerOwnsAsset instead. The first thing I tried was to do it like

if game.MarketplaceService:PlayerOwnsAsset(player,5429209) then

end

and it doesn't print an error, but the game doesn't think I own the gamepass, and ignores the if statement.

Script:

local testers = {"FoxOwO","S_naZY","jurassicsonic","Knineteen19","Black_Xenon","Phoen_ix25","Dragonwizarder","NovaGaming1234","Axiom_Vang"}
local passService = game:GetService("GamePassService")

game.Players.PlayerAdded:connect(function(player)
	player.CharacterAdded:connect(function(char)
		local multi = script:WaitForChild("XP Multiplier")
		local multiplier = multi:Clone()
		
		if player.Name == "Knineteen19" then
			multiplier.Value = multiplier.Value * 10
			print(multiplier.Value)
		end
	
		for i,Testers in pairs(testers) do
			if Testers == player.Name then
				multiplier.Value = multiplier.Value * 2
				print(multiplier.Value)
				break
			end
		end
		
		if passService:PlayerHasPass(player,5429209) then
			multiplier.Value = multiplier.Value * 2
			print(multiplier.Value)
		end
		
		multiplier.Parent = game.Workspace:WaitForChild(player.Name).Humanoid
	end)
end)

Any help would be appreciated!

1 answer

✓ Accepted answer

Yea, roblox's new gamepass system is very messed up and dumb. For example GamePassService:PlayerHasPass() will only give you an accurrate result if you use the asset id and not gamepass id of the gamepass. So I honestly don't know why they added that function in the first place.

Another thing about the asset ids and gamepass ids is their api. There are two endpoints for getting the info about the gamepass: the first one takes the gamepass id, the other one takes the asset id. Now, they return the exact same info, with one difference: the first one doesn't return the asset id! It would be very useful if it did, because then you could use it with MarketplaceService:PlayerOwnsAsset().

So, what you need to do is use MarketplaceService:UserOwnsGamePassAsync()

Note that it takes the player's UserId as the first argument, rather than a player object itself.

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,5429209) then
	--stuff
end

Btw, I just found some "clarification" about this on roblox wiki over here. Though it's still dumb that they hid it under some function documentation.

1 comment

0

Kind of weird, but it worked. Thanks!

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