Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Function only fires when the first string in the table is fired, but not the second or third?

Asked by
Galicate 106
6 years ago

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.

001local Clearances = {
002    ["Tier 3 Administrator"] = true,
003    ["Tier 2 Administrator"] = true,
004    ["Tier 1 Administrator"] = true,
005    ["Tier 3 Security"] = true,
006    ["Tier 2 Security"] = true,
007    ["Tier 1 Security"] = true,
008    ["Armoury Access"] = true,
009    ["Level 5"] = true,
010    ["Level 4"] = true,
011    ["Level 3"] = true,
012    ["Level 2"] = true,
013    ["Level 1"] = true,
014}
015local LockDownCards = {"Tier 3 Administrator","Tier 2 Administrator","Tier 1 Administrator"}
View all 123 lines...

1 answer

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

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.

01-- Added before the Activated function.
02function checkForLockDownParent(Part) -- Check for whether the part belongs to one of these parents in LockDownCards.
03    for i, cardName in pairs(LockDownCards) do
04        if Part.Parent.Name == cardName then
05            return true -- Stop the function and this will become the value true when called.
06        end
07    end
08    return false -- Belongs to none, the value becomes false.
09end
10 
11-- Below is Line 25 in your original code (in your question).
12function Activated(Part)
13    if DoorIsOpen == false and DoorIsBusy == false and LockDown_Enabled == false and Clearances[Part.Parent.Name] then
14        Open()
15    elseif DoorIsBusy == false and DoorIsOpen == true and LockDown_Enabled == false and Clearances[Part.Parent.Name] then
View all 26 lines...

I hope this will solve your problem. Comment if you have any questions. Thanks.

0
Thanks man, it worked perfectly. Galicate 106 — 6y
0
You are welcome. ;3 starlebVerse 685 — 6y
Ad

Answer this question