--"False" = Not Acceptable Keycard To Open. "True" = Acceptable Keycard To Open.--


local door = script.Parent
local bool = false
local CanOpen1 = true
local CanClose1 = false
local AccessDenied = script.Parent.AccessDenied
local AccessGranted = script.Parent.AccessGranted
local clearance = {
	["[SCP] Card-Omni"] = true, 
	["[SCP] Card-L5"] = true, 
	["[SCP] Card-L4"] = true,
	["[SCP] Card-L3"] = true,
	["[SCP] Card-L2"] = true,
	["[SCP] Card-L1"] = true
}
						
						--DO NOT EDIT PAST THIS LINE--
function openDoor()
	script.Parent.DoorOpen:play()
	for i = 3,(door.Size.z / 0.15) do
		wait()
		door.CFrame = door.CFrame - (door.CFrame.lookVector * 0.15)
	end
end

function closeDoor()
	script.Parent.DoorClose:play()
	for i = 3,(door.Size.z / 0.15) do
		wait()
		door.CFrame = door.CFrame + (door.CFrame.lookVector * 0.15)
	end
end

script.Parent.Parent.KeycardReader1.touched:connect(function(touch)
	if touch.Name == "Handle" and clearance[touch.Parent.Name] and CanOpen1 == true then
		
		CanOpen1 = false
		AccessGranted:Play()
		wait(0.75)
		openDoor()
		wait(1)
		CanClose1 = true
	elseif touch.Name == "Handle" and clearance[touch.Parent.Name] and CanClose1 == true then
		CanClose1 = false
		AccessGranted:Play()
		wait(0.75)
		closeDoor()
		wait(1)
		CanOpen1 = true
	elseif touch.Name == "Handle" and clearance[touch.Parent.Name] == false and not bool then
		bool = true
		AccessDenied:Play()
		wait(2)
		bool = false
	end
end)

script.Parent.Parent.KeycardReader2.touched:connect(function(touch)
	if touch.Name == "Handle" and clearance[touch.Parent.Name] and CanOpen1 == true then
		CanOpen1 = false
		AccessGranted:Play()
		wait(0.75)
		openDoor()
		wait(1)
		CanClose1 = true
	elseif touch.Name == "Handle" and clearance[touch.Parent.Name] and CanClose1 == true then
		CanClose1 = false
		AccessGranted:Play()
		wait(0.75)
		closeDoor()
		wait(1)
		CanOpen1 = true
	elseif touch.Name == "Handle" and clearance[touch.Parent.Name] == false and not bool then
		bool = true
		AccessDenied:Play()
		wait(2)
		bool = false
	end
end)
