Im trying to make a door that locks during a lockdown and only certain cards can open the door. But for some reason it only opens during a lockdown for a Tier 3 Administrator but none of the others.
local Clearances = { ["Tier 3 Administrator"] = true, ["Tier 2 Administrator"] = true, ["Tier 1 Administrator"] = true, ["Tier 3 Security"] = true, ["Tier 2 Security"] = true, ["Tier 1 Security"] = true, ["Armoury Access"] = true, ["Level 5"] = true, ["Level 4"] = true, ["Level 3"] = true, ["Level 2"] = true, ["Level 1"] = true, } local LockDownCards = {"Tier 3 Administrator","Tier 2 Administrator","Tier 1 Administrator"} local DoorPart1 = script.Parent.Door local DoorPart2 = script.Parent.Window local StatusPart = script.Parent.StatusPart local DoorIsBusy = false local DoorIsOpen = false local LockDown_Enabled = false for i, value in pairs(LockDownCards) do print(LockDownCards[i]) end function Activated(Part) if DoorIsOpen == false and DoorIsBusy == false and LockDown_Enabled == false and Clearances[Part.Parent.Name] then Open() elseif DoorIsBusy == false and DoorIsOpen == true and LockDown_Enabled == false and Clearances[Part.Parent.Name] then Close() elseif DoorIsBusy == false and LockDown_Enabled == true and Part.Parent.Name ~= LockDownCards[1 or 2 or 3] and Clearances[Part.Parent.Name] then LockDown() elseif DoorIsBusy == false and LockDown_Enabled == true and DoorIsOpen == false and Part.Parent.Name == LockDownCards[1 or 2 or 3] and Clearances[Part.Parent.Name] then Open() elseif DoorIsBusy == false and LockDown_Enabled == true and DoorIsOpen == true and Part.Parent.Name == LockDownCards[1 or 2 or 3] and Clearances[Part.Parent.Name] then Close() end end function Open() DoorIsBusy = true DoorPart1.DoorMove_Sound:Play() for i = 10, 50 do wait(0.01) DoorPart1.CFrame = DoorPart1.CFrame * CFrame.new(-0.1,0,0) DoorPart2.CFrame = DoorPart2.CFrame * CFrame.new(-0.1,0,0) StatusPart.CFrame = StatusPart.CFrame * CFrame.new(-0.1,0,0) end wait(1) StatusPart.SurfaceGui1.Open.Text = "[ OPEN ]" StatusPart.SurfaceGui1.Open.TextColor3 = Color3.new(0, 255, 0) StatusPart.SurfaceGui2.Open.Text = "[ OPEN ]" StatusPart.SurfaceGui2.Open.TextColor3 = Color3.new(0, 255, 0) DoorIsBusy = false DoorIsOpen = true end function Close() DoorIsBusy = true DoorPart1.DoorMove_Sound:Play() for i = 10, 50 do wait(0.01) DoorPart1.CFrame = DoorPart1.CFrame * CFrame.new(0.1,0,0) DoorPart2.CFrame = DoorPart2.CFrame * CFrame.new(0.1,0,0) StatusPart.CFrame = StatusPart.CFrame * CFrame.new(0.1,0,0) end wait(1) StatusPart.SurfaceGui1.Open.Text = "[ CLOSED ]" StatusPart.SurfaceGui1.Open.TextColor3 = Color3.new(255, 0, 0) StatusPart.SurfaceGui2.Open.Text = "[ CLOSED ]" StatusPart.SurfaceGui2.Open.TextColor3 = Color3.new(255, 0, 0) DoorIsBusy = false DoorIsOpen = false end function LockDown() if DoorIsOpen == false then DoorPart1.LockDown_Sound:Play() DoorIsBusy = true DoorPart1.DoorMove_Sound:Play() for i = 10, 25 do wait(0.01) DoorPart1.CFrame = DoorPart1.CFrame * CFrame.new(-0.1,0,0) DoorPart2.CFrame = DoorPart2.CFrame * CFrame.new(-0.1,0,0) StatusPart.CFrame = StatusPart.CFrame * CFrame.new(-0.1,0,0) end for i = 10, 25 do wait(0.01) DoorPart1.CFrame = DoorPart1.CFrame * CFrame.new(0.1,0,0) DoorPart2.CFrame = DoorPart2.CFrame * CFrame.new(0.1,0,0) StatusPart.CFrame = StatusPart.CFrame * CFrame.new(0.1,0,0) end wait(1) StatusPart.SurfaceGui1.Open.Text = "[ CLOSED ]" StatusPart.SurfaceGui1.Open.TextColor3 = Color3.new(255, 0, 0) StatusPart.SurfaceGui2.Open.Text = "[ CLOSED ]" StatusPart.SurfaceGui2.Open.TextColor3 = Color3.new(255, 0, 0) DoorIsBusy = false end end function LockDownActive() if workspace.SiteStats.LockDown.Value == true then LockDown_Enabled = true StatusPart.SurfaceGui1.Locked.Text = "[ LOCKED ]" StatusPart.SurfaceGui1.Locked.TextColor3 = Color3.new(255, 85, 0) StatusPart.SurfaceGui2.Locked.Text = "[ LOCKED ]" StatusPart.SurfaceGui2.Locked.TextColor3 = Color3.new(255, 85, 0) if DoorIsOpen == true and DoorIsBusy == false then print("Closing Door") Close() end elseif workspace.SiteStats.LockDown.Value == false then LockDown_Enabled = false StatusPart.SurfaceGui1.Locked.Text = "[ UNLOCKED ]" StatusPart.SurfaceGui1.Locked.TextColor3 = Color3.new(255, 255, 0) StatusPart.SurfaceGui2.Locked.Text = "[ UNLOCKED ]" StatusPart.SurfaceGui2.Locked.TextColor3 = Color3.new(255, 255, 0) end end script.Parent.CardReader1.Touched:Connect(Activated) script.Parent.CardReader2.Touched:Connect(Activated) workspace.SiteStats.LockDown.Changed:Connect(LockDownActive)
For lines 30, 32 and 34, you cannot do LockDownCards[1 or 2 or 3]
because the game will then have to choose the first option in the 1 or 2 or 3
part, which is 1
. It would be the same as saying LockDownCards[1]
. To read more about the or
operator, click here. There is another way to check this, of course.
-- Added before the Activated function. function checkForLockDownParent(Part) -- Check for whether the part belongs to one of these parents in LockDownCards. for i, cardName in pairs(LockDownCards) do if Part.Parent.Name == cardName then return true -- Stop the function and this will become the value true when called. end end return false -- Belongs to none, the value becomes false. end -- Below is Line 25 in your original code (in your question). function Activated(Part) if DoorIsOpen == false and DoorIsBusy == false and LockDown_Enabled == false and Clearances[Part.Parent.Name] then Open() elseif DoorIsBusy == false and DoorIsOpen == true and LockDown_Enabled == false and Clearances[Part.Parent.Name] then Close() elseif DoorIsBusy == false and LockDown_Enabled == true and checkForLockDownParent(Part) == false and Clearances[Part.Parent.Name] then -- Notice that the "== false" is added behind checkForLockDownParent(Part) so the game checks whether the value returned is false. LockDown() elseif DoorIsBusy == false and LockDown_Enabled == true and DoorIsOpen == false and checkForLockDownParent(Part) and Clearances[Part.Parent.Name] then Open() elseif DoorIsBusy == false and LockDown_Enabled == true and DoorIsOpen == true and checkForLockDownParent(Part) and Clearances[Part.Parent.Name] then Close() end end -- Continues on...
I hope this will solve your problem. Comment if you have any questions. Thanks.