Help for everyone "Gamepass Door"

First, keep in mind that to understand the following code sequence, you must know the script.

I have noticed that, in the community, several people have problems with purchases of development products and games in the game.

When a code has the following part:
game: GetService (“MarketplaceService”):PromotPurchase

  • This refers to the purchase of a developer product

On the other hand, when he says this part:

game: GetService (“MarketplaceService”):PromotGamePassPurchase

  • Refers to the purchase of a gamepass.

Gamepass door Code Complete:


local GamePassID = – The ID of the Gamepass/T-Shirt.
OpenTime = 1 – The time the door is open for.
OpenTrans = 1 – The transparency of the door when it is open.
CloseTrans = .45 – The transparency of the door when it is closed.
BuyGUI = true – Set to false to stop the BuyGUI appearing.
KillOnTouch = true – Set to false to stop players being killed when they touch it.


Door = script.Parent
MServ:UserOwnsGamepassAsync(player.UserId, ItemId) or CheckPlayer(player) then
if not _G.Players then
_G.Players = {[ItemID] = {}}
elseif not _G.Players[ItemID] then
_G.Players[ItemID] = {}
end

Table = _G.Players[ItemID]

function CheckPlayer(player2)
for i = 1,#Table do
if Table[i] == player2 then
return true
end
end
return false
end

Door.Touched:connect(function(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
player = game.Players:GetPlayerFromCharacter(hit.Parent)
if Serv:UserHasBadge(player.userId,ItemID) or CheckPlayer(player) then
Door.CanCollide = false Door.Transparency = OpenTrans
wait(OpenTime)
Door.CanCollide = true Door.Transparency = CloseTrans
else
Door.CanCollide = true Door.Transparency = CloseTrans
if BuyGUI == true then
MServ:PromptGamePassPurchase(player,ItemID)
h = player.Character:FindFirstChild(“Humanoid”)
if h then
h.WalkSpeed = 0 end
local con
con = MServ.PromptGamePassPurchaseFinished:connect(function(ply,asset,purch)
if ply == player and asset == ItemID then
con:disconnect()
if purch then
if h then
h.WalkSpeed = 16 end
table.insert(Table,player)
elseif KillOnTouch == true then
Door.CanCollide = true Door.Transparency = CloseTrans
player.Character:BreakJoints()
end
end
end)
elseif KillOnTouch == true then
Door.CanCollide = true Door.Transparency = CloseTrans
player.Character:BreakJoints()
end
end
end
end)

Doubts below :slight_smile:
Bye!

1 Like

Looks really good and I am sure this will help a ton of people! :smile:

The only thing I suggest is using a local script and destroying or setting the collision of the part so the player will not have a very short wait time standing at the door, waiting for the script to give them access.

Thank you very much, what you say is to the likes of the player if someone does not want that he omitted it and I will help him with pleasure, Greetings!
:slight_smile:

I sent you friend request :smile:

I think this topic is in wrong category, you should move this topic to learning resources / Community tutorials

As stated above, please use the Scripting Support category for the reasons mentioned in the About post:

To post in a category you don’t have access to, please use the post approval process mentioned in the rules.