How to check for gamepass when part is touched?

  1. What do you want to achieve?
    I’m trying to make a button that does something if a player touches it and owns a gamepass.

  2. What is the issue?
    The issue is that when I test it out, nothing happens and it says “Userid is not a valid member of MeshPart”

  3. What solutions have you tried so far?
    I tried to figure it out on my own, but I ended up looking for a solution on the Developer Forum. However, I still couldn’t find anything that worked.

Here is what I have right now:

script.Parent.Touched:Connect(function(player)
	local PlayerBoughtThisGamePass = MarketPlaceService:UserOwnsGamePassAsync(player.Userid, 10981103)
	if PlayerBoughtThisGamePass then
		script.Parent:Destroy()
	end
end)
1 Like

Firstly lets call the function event because the argument it is giving is an event not the player.

script.Parent.Touched:Connect(function(part)

Now we need to get the player.

local player = game.Players:GetPlayerFromCharacter(part.Parent) --part.Parent = character

Hope it helps :slight_smile:
(the part goes inside the player when they touch it so when you defined it as player, you mean the actual part)

2 Likes

Sorry, I don’t know if I’m doing this right but now it says: “Userid is not a valid member of Player” even though UserId is a property of Player.

Wait never mind I just made a typo. Thank you for your help! :grinning:

Your welcome! Have a great time :smiley:

1 Like