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

GamePassService:PlayerHasPass is not working, why is that?

Soo i'm trying to make a script where if you have bought a certain pass, it gives you a tool

script:

local coilButton = script.Parent.CoilButton
local coil = game.ReplicatedStorage.BootlegCoil
local coilId = 9517388

local MS = game:GetService("MarketplaceService")
local GS = game:GetService("GamePassService")
local player = game.Players.LocalPlayer

local function promptGamepass()
	MS:PromptGamePassPurchase(player, coilId)
end

local function checkGamepasses()
	if GS:PlayerHasPass(player, coilId) then 
		print("player has coil!")
		local clone = coil:Clone()
		if clone.Parent ~= player.Backpack then
			clone.Parent = player.Backpack
		end
	end
end

coilButton.MouseButton1Click:Connect(promptGamepass)
game.Players.PlayerAdded:Connect(checkGamepasses)

Can someone tell me why check gamepasses function is not giving me the tool and not printing anything?

2 answers

✓ Accepted answer

It's been known for a couple years now that it is no longer :PlayerHasPass and is now :UserOwnsGamepassAsync.

Example:

local MPS = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer
local gamepassid == 00000

MPS:UserOwnsGamepassAsync(player.UserId, gamepassid)
--something
end)

So, for you:

local coilButton = script.Parent.CoilButton
local coil = game.ReplicatedStorage.BootlegCoil
local coilId = 9517388

local MS = game:GetService("MarketplaceService")
local GS = game:GetService("GamePassService")
local player = game.Players.LocalPlayer

local function promptGamepass()
    MS:PromptGamePassPurchase(player, coilId)
end

local function checkGamepasses()
    if MS:UserOwnsGamepassAsync(player.UserId, coilid) then 
        print("player has coil!")
        local clone = coil:Clone()
        if clone.Parent ~= player.Backpack then
            clone.Parent = player.Backpack
        end
    end
end

coilButton.MouseButton1Click:Connect(promptGamepass)
game.Players.PlayerAdded:Connect(checkGamepasses)

Hoped this helped, please tell me if i made an error!

I used a different function. Try it.

Based from: https://developer.roblox.com/en-us/api-reference/class/GamePassService

Sample of using the function:

local a = game:GetService("Players");
local b = game:GetService("MarketplaceService");
local c = game:GetService("GamePassService");

local GamePassId = 6512404; -- this type is a gamepass id, not an asset id
 -- Note: I own this gamepass because I made it. ids vary

local d; -- player, it varies
repeat -- this part is for getting the player, it yields the script until the 
	   -- player appears. this is for example purposes
	d = a:FindFirstChild('SoftlockedUnderOne');
	wait(1);
until d;

if b:UserOwnsGamePassAsync(d.UserId,GamePassId)then -- this function gives a warning, so you may have to re adjust if desired
	print('Marketplace function returned true');-- prints
end;
if c:PlayerHasPass(d,GamePassId)then
	print('GamepassService function returned true');-- does not print
end;

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