Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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)

6 comments

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?

0

Line 20-27 looks fishy...

0

The whitelist is for people that will be let in without a game pass.

0

Line 7. CloseTrans is supposed to be 0

0

Oh I did not notice that.

0

If your problem is fixed, write [Solved] in your title.

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.