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

Isn't this how you use GamePassService:PlayerHasPasS?

I can't seem to make this right. I've spent over 30 minutes trying to figure out what I'm doing wrong and I can't figure it out. Please help!

script:

local GamepassID = 898980796
local Door = script.Parent
local GPS = game:GetService("GamePassService")

script.Parent.Touched:connect(function(Player)
	if Player.Parent:FindFirstChild("Humanoid") then
		local RealPlayer = game.Players:GetPlayerFromCharacter(Player)
		if GPS:PlayerHasPass(RealPlayer, GamepassID) then
			print("Opening door for", Player)
			Door.CanCollide = false
			Door.Transparency = 0.5
			wait(2)
			Door.CanCollide = true
			Door.Transparency = 1
		else
			Player.Parent:BreakJoints()
		end
	end
end)

output: AssetId '899341030' is of type Game Pass. Please use GamePassService:PlayerHasPass instead.

Not a valid Player - Referring to line 8.

1 comment

0

local RealPlayer = game.Players:GetPlayerFromCharacter(Player.Parent) Player.Parent is potentially the players character. Player is whatever touched the part, a leg for example, which is why that parameter is commonly named hit.

1 answer

On the wiki, it states that it is highly recommended to use PlayerHasAsset instead.

local id = 000000
game.Players.PlayerAdded:connect(function(plr)
	if game:GetService("MarketplaceService"):PlayerOwnsAsset(plr,id) then
		print("Player has gamepass!")
--rest of your code here
	else
		print("Player doesn't have gamepass")
--rest of your code here
	end
end)

If this helped, please upvote and accept answer!

3 comments

0

PlayerHasAsset isn't a member of the API. And connect is deprecated, use Connect.

0

PlayerOwnsAsset is preferred over PlayerHasPass because it returns live results from the website, instead of cached results from the start of the server.

0

This notice was removed, because PlayerOwnsAsset does not work for GamePasses anymore.

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