Game pass door that works with several gamepasses

Hello !

I am the head dev. of world at war community. We’re currently facing several problems with the game pass doors I modified. You have to know that when we own a game pass, you can enter the room. If you dont, it kills you.

The problem is here : Doors work with several game pass ID (3 different Game passes) each, and sometimes(/always ?) kills players that own one of these pass. I dont know where is the problem exactly. Here is the code :

-- -----------------------------------------------------------------------------------------------

local MS = game:GetService("MarketplaceService")
local Gamepass = 7988902 -- The ID of the Gamepass.
local Gamepass2 = 8439939 -- The ID of the 2nd Gamepass.
local Gamepass3 = 8440060 -- The ID of the 3rd Gamepass.
local OpenTime = 1 -- The time the door is open for.
local OpenTrans = 0.5 -- The transparency of the door when it is open.
local CloseTrans = 0 -- The transparency of the door when it is closed.
local BuyGUI = false -- Set to false to stop the BuyGUI appearing.
local KillOnTouch = true -- Set to false to stop players being killed when they touch it.
local Whitelist = {
    1 --ROBLOX
} -- USERID || People that can open the door without owning the badge.

-----------------------------------------------------------------------------------------------

local Door = script.Parent -- The door

-----------------------------------------------------------------------------------------------

function CheckWhitelist(v)
    for i = 1, #Whitelist do
        if v == Whitelist[i] then
            return true
        end
    end
    return false
end

Door.Touched:Connect(function(hit)
    if game.Players:GetPlayerFromCharacter(hit.Parent) then
        local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
        if Gamepass <= 0 then return nil end
        if MS:UserOwnsGamePassAsync(plr.UserId, Gamepass) or MS:UserOwnsGamePassAsync(plr.UserId, Gamepass2) or MS:UserOwnsGamePassAsync(plr.UserId, Gamepass3) or CheckWhitelist(plr.UserId) then
            Door.CanCollide, Door.Transparency = false, OpenTrans
            wait(OpenTime)
            Door.CanCollide, Door.Transparency = true, CloseTrans
        else
            Door.CanCollide, Door.Transparency = true, CloseTrans
            if BuyGUI == true then
                MS:PromptGamePassPurchase(plr, Gamepass)
            end
            if KillOnTouch == true then
                plr.Character.Humanoid.Health = 0
            end
        end
    end
end)

I’ll be glad if you can help me about this. I want to make all the game passes working together, in one door. Thanks for replying !

1 Like

Try adding in a debounce because touched events run even during the touch, which can get pretty crazy sometimes and runs the function way too many times.

1 Like

By debounce, you mean something like a “cooldown” ? Or it breaks the action ? Sorry, i’m verry new at scripting. I more into meshing ^^’

1 Like

Use this:

local MS = game:GetService("MarketplaceService")
local Door = script.Parent
local GPs = {4536457645,6546546546,45664} --enter gamepass ids here separated by a comma.
local db = false
Door.Touched:Connect(function(hit)
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if plr then
for i,v in pairs(GPs) do
if MS:UserOwnsGamePassAsync(plr.UserId, v) then
Door.Transparency = 0
Door.CanCollide = false
return
end
end
plr.Character:BreakJoints()
end
end)
3 Likes

I love the way you use tables for IDs, I think it could be better ! Thanks, I will try it !

2 Likes

How do you add more then one user?