Help with Gamepass Door

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    A part that prompts the player who touched it to buy a gamepass, unless they already have it.

  2. What is the issue? Include screenshots / videos if possible!
    I’m not sure how to do this…

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?

This is my current script (inside a door part). It opens if they have the gamepass, but I want it to prompt a purchase if they don’t… What should I add to the section with print("Player has no gamepass!") so that it does?

local MarketPlaceService = game:GetService("MarketplaceService")
local GamepassId = 11589657 --id here

local debounce = false
	if hit.Parent:FindFirstChild("Humanoid") then
		if debounce == false then
			debounce = true
			local player = game.Players:GetPlayerFromCharacter(hit.Parent)
			if MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassId) then
				--open door
				script.Parent.Transparency = 0.9
				script.Parent.CanCollide = false
				wait (0.5)
				script.Parent.Transparency = 0.7
				script.Parent.CanCollide = true
				wait (0.1)
				debounce = false
				print("Player has no gamepass!")
				wait (0.5)
				debounce = false			

FYI I did not create this code myself…

1 Like

Ignore me holdon… I said something stupid

Well what’s the issue here, what’s not happening? What does the output look like?

Yes they did, if debounce is true the code is just skipped.

I updated my reply, I’m gonna actually try to help now

1 Like

If you are confused how how to prompt a gamepass purchuse you can do it with MarketplaceService:PromptGamepassPurchuse. This would go in the spot of the where you currently have the print("Player has no gamepass!").


That’s it? Would “player” work because I already defined player as GetPlayerFromCharacter?