New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

So How come my Vip door won't work, what went wrong exactly?(Filtering Enabled)

Asked by 8 days ago

So I have a door that when touched it will check if you have a game pass and if you do have the game pass it will open up, but won't close, and only opens I really don't know why it won't work.

----Script----

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

local MS = game:GetService("MarketplaceService")
local Gamepass = 0 -- The ID of the Gamepass. --- I have an ID placed in my game already.
local OpenTime = 10 -- The time the door is open for.
local OpenTrans = 1 -- The transparency of the door when it is open.
local CloseTrans = 1 -- The transparency of the door when it is closed.
local BuyGUI = true -- Set to false to stop the BuyGUI appearing.
local KillOnTouch = false -- 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 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)
0
I don't see a close function. It just repeats open and never closes unless the statement is false ill try to rewrite the code through. Also are you trying to check a badge or a gamepass? voidofdeathfire 107 — 8d
0
Line 20-27 looks fishy... greatneil80 1439 — 8d
0
The whitelist is for people that will be let in without a game pass. vincentthecat1 79 — 8d
0
Line 7. CloseTrans is supposed to be 0 Shawnyg 3935 — 8d
View all comments (2 more)
0
Oh I did not notice that. vincentthecat1 79 — 8d
0
If your problem is fixed, write [Solved] in your title. Feahren 1746 — 8d

1 answer

Log in to vote
1
Answered by 8 days ago

Heres a polished version of your script. You put a lot of unnecessary things to prevent errors and such.

local marketplace = game:GetService("MarketplaceService")
local gamepassid = 1 -- insert id here or it will error.
local waittime = 0.5
local door = script.Parent
local whitelist = {}

function checkwhitelist(userId)
    for _,v in pairs(whitelist) do
        if v == userId then
            return true
        end
    end
    return false
end


door.Touched:Connect(function(hit)
    local player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player ~= nil then
        if gamepassid ~= 0 then
        if marketplace:UserOwnsGamePassAsync(player.UserId,gamepassid) or checkwhitelist(player.UserId) == true then
            script.Parent.Transparency = .5
            door.CanCollide = false
            door.Transparency = 1
            wait(waittime)
            door.Transparency = 0
            door.CanCollide = true
        else
            door.Transparency = 0
            door.CanCollide = true
        end
        end
        end
end)
Ad

Answer this question