GamePassService not working

Hello,
I am doing a gamepass system for my egg in my game that gives the user more chance of getting the rare pet.
Here is the script.

local enabled = false

local id = 8812746

script.Parent.ClickDetector.MouseClick:Connect(function(plr)
	if not enabled then
		enabled = true
		rarity = math.random(0,100)
		if plr.leaderstats.Coins.Value >= 4000 then
			plr.leaderstats.Coins.Value = plr.leaderstats.Coins.Value - 4000
			ui = game.ReplicatedStorage.UI.EggUI.Basic100:Clone()
			ui.Egg.Visible = false
			ui.Egg.Position = UDim2.new(0.341,0,1.1)
			ui.Parent = plr.PlayerGui
			for i = 1.1, 0.12,-0.05 do
				ui.Egg.Visible = true
				wait(0.01)
				ui.Egg.Position = UDim2.new(0.341, 0, i, 0)
			end
                        if game:GetService("GamePassService"):PlayerHasPass(plr, id) or then
				rarity = math.random(60,100)
			end
                        ui.Egg.Visible = false 
			if rarity <= 25 then
				darkOverUI = game.ReplicatedStorage.UI.EggUI.Rich4k.DarkOverlord:Clone()
				darkOverUI.Visible = true
				darkOverUI.Parent = plr.PlayerGui
				darkOver = game.ReplicatedStorage.Pets.Legendarys.DarkOverlord:Clone()
				darkOver.Parent = plr.pets
				wait(5)
				darkOverUI:Destroy()
			elseif rarity >= 26 and rarity <= 50 then
				fireOverUI = game.ReplicatedStorage.UI.EggUI.Rich4k.FireOverlord:Clone()
				fireOverUI.Visible = true
				fireOverUI.Parent = plr.PlayerGui
				fireOver = game.ReplicatedStorage.Pets.Legendarys.FireOverlord:Clone()
				fireOver.Parent = plr.pets
				wait(5)
				fireOverUI:Destroy()
			elseif rarity == 51 and rarity <= 75 then
				holyGolUI = game.ReplicatedStorage.UI.EggUI.Rich4k.HolyGolem:Clone()
				holyGolUI.Visible = true
				holyGolUI.Parent = plr.PlayerGui.petUI
				holyGol = game.ReplicatedStorage.Pets.Legendarys.HolyGolem:Clone()
				holyGol.Parent = plr.pets
				wait(5)
				holyGolUI:Destroy()
			elseif rarity == 76 and rarity <= 99 then
				rainOverUI = game.ReplicatedStorage.UI.EggUI.Rich4k.RainbowOverlord:Clone()
				rainOverUI.Visible = true
				rainOverUI.Parent = plr.PlayerGui.petUI
				rainOver = game.ReplicatedStorage.Pets.Legendarys.RainbowOverlord:Clone()
				rainOver.Parent = plr.pets
				wait(5)
				rainOverUI:Destroy()
			elseif rarity == 100 then
				toxixHydraUI = game.ReplicatedStorage.UI.EggUI.Rich4k.ToxicHydra:Clone()
				toxixHydraUI.Visible = true
				toxixHydraUI.Parent = plr.PlayerGui.petUI
				toxixHydra = game.ReplicatedStorage.Pets.Secrets.ToxicHydra:Clone()
				toxixHydra.Parent = plr.pets
				wait(5)
				toxixHydraUI:Destroy()
			end
		end
	end
	enabled = false
end)

This is the error I get
image
Why is it telling me that the Id is not valid and why should I use PlayerOwnsAsset? It’s not an asset.
Here is the gamepass link: https://www.roblox.com/game-pass/8812746/Lucky

Thanks for your help.

1 Like

Hey, I suggest using UserOwnsGamePassAsync.

2 Likes

Replace GamePassService with MarketplaceService:UserOwnsGamePassAsync

2 Likes

Also, not sure if you deleted it on purpose or something, but there’s a random “or” in there that doesn’t do anything, but will error your script.Capture

Oh that was just me by accident when I was writing it on the DevForum.

Ah, alright, but yeah, use UserOwnsGamePassAsync to handle gamepasses.

1 Like

People have said the alternative already, but in case you’re curious, the reason GamePassService doesn’t work is because gamepasses were a type of asset when it was made. For backwards compatibility, it still works on old gamepasses’ asset ids (these gamepasses now have both an asset id and a gamepass id associated).

4 Likes

Here is what I tried but still does not work.

--My useless code up there
local id =  8812746

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, id) then
    rarity = math.random(60,100)
end
--Useless code below

Am I doing something wrong?

I just tested it in studio and it seems to work, make sure you actually own the gamepass, since it’s a gamepass attached to the game/group, you might actually not own it.

1 Like