In my game each door has a key card reader. In each it will check what level key card you have and if it is the right level it will open the door. I am making an interrogation room so I am making a key card reader that will disable the door opening script in the specific door and then enable the script with a higher level clearance level. I hope that makes sense. For some reason the lock key card reader isn't working and I am unsure why. This is the script I'm using.
local beepsound = game.Workspace.Sounds.Beep
local accessgrantedbeep = game.Workspace.Sounds.AccessGrantedBeep
local accessdeniedbeep = game.Workspace.Sounds.AccessDeniedBeep -- I have a folder for sounds in workspace to make it easy to use the same sounds in different scripts
local Light1 = script.Parent.Light1
local Light1A = script.Parent["Light1:A"]
local Light1B = script.Parent["Light1:B"] -- On the keycard reader there are lights which give you a visual indication if your card was accepted or not
local shieldDoor = game.Workspace["Interveiw Rooms"].SHIELDDoor1 -- The door that it is locking
local bool = true
local bool2 = true
local clearance = {
["L0"] = false,
["L1"] = false,
["L2"] = false,
["L3"] = false,
["L4"] = false,
["L5"] = true,
["L6"] = true,
["L7"] = true,
["L8"] = true,
["L9"] = true,
["L10"] = true
}
-- This table shows which key card levels are accepted and which aren't
function lockDoor()
shieldDoor.SComponents.Door.DoorScript.Disabled = true
shieldDoor.SComponents.Door.DoorScriptLocked.Disabled = false
end -- this function is so I can call it later to enable one script and disable the other
function unlockDoor()
shieldDoor.SComponents.Door.DoorScript.Disabled = false
shieldDoor.SComponents.Door.DoorScriptLocked.Disabled = true
end -- this one does the opposite of the previous
script.Parent.TouchDetector.Touched:Connect(function(touch) -- I have a part named TouchDetector which is invisible and is put over the key card reader. This is the part that isn't working for me. It wont start the rest of the function when it is touched.
if touch.Name == "Handle" and clearance[touch.Parent.Name] and bool then
bool = false
if script.Parent.Unlocked == true then
script.Unlocked = false
beepsound:Play()
Light1.brickColor = BrickColor.new("Deep orange")
Light1.Material = Enum.Material.Neon;
wait(1)
beepsound:Play()
Light1B.brickColor = BrickColor.new('Lime green')
Light1B.Material = Enum.Material.Neon;
accessgrantedbeep:Play()
Light1.BrickColor = BrickColor.new("Really red")
Light1A.BrickColor = BrickColor.new("Really red")
Light1B.BrickColor = BrickColor.new("Really red")
Light1A.Material = Enum.Material.Neon
lockDoor()
end -- this changes the lights to show its locked
if script.Parent.Unlocked == false then -- the debounce checks a bool value to see if the door is already unlocked or not.
script.Unlocked = true
beepsound:Play()
Light1.BrickColor = BrickColor.new('black')
Light1A.BrickColor = BrickColor.new('black')
Light1B.BrickColor = BrickColor.new('black')
Light1.Material = Enum.Material.SmoothPlastic
Light1A.Material = Enum.Material.SmoothPlastic
Light1B.Material = Enum.Material.SmoothPlastic
unlockDoor()
end -- turns lights back to normal
bool = true
elseif touch.Name == "Handle" and not clearance[touch.Parent.Name] and bool2 then
bool2 = false
beepsound:Play()
Light1.brickColor = BrickColor.new("Deep orange")
Light1.Material = Enum.Material.Neon;
wait(1)
accessdeniedbeep:Play()
Light1A.brickColor = BrickColor.new('Really red')
Light1A.Material = Enum.Material.Neon;
-- this is the visual indication that your card was declined
wait(1)
Light1.brickColor = BrickColor.new("Black")
Light1.Material = Enum.Material.SmoothPlastic
Light1A.brickColor = BrickColor.new('Black')
Light1A.Material = Enum.Material.SmoothPlastic
-- turns lights back to normal
wait(1)
bool2 = true
end
end)
The original script wasn't mine however I heavily modified it. No errors are showing so I am unsure why it isn't setting off the function. Sorry if it wasn't explained well.
