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

This door opens for everyone not just the people in the list. Any idea why?

Asked by 6 years ago
01                            --<tkcmdr>--
02 
03local door = script.Parent
04local bool = true
05local bool2 = true
06local clearance = {
07    ["[SCP] Card-Omni"] = true,
08    ["[SCP] Card-L5"] = true,
09    ["[SCP] Card-L4"] = true,
10    ["[SCP] Card-L3"] = true,
11    ["[SCP] Card-L2"] = false,
12    ["[SCP] Card-L1"] = false,
13    ["[SCP] MTF Access Card"] = false,
14    ["[SCP] O5-2 Access Card"] = true,
15    ["[SCP] ET Card"] = false,
View all 62 lines...
0
This is a common problem. I recommend learning a bit more about or/and statements. User#21908 42 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago

The problem is in your if statements. When you are using or you are forgetting that it is a whole new check system. Let me explain with a little code:

1--here is an if statement:
2if player.Name == "Name" then -- this works
3--let's create a new if statement but this time with two names
4if player.Name == "Name" or "Name2" then -- this always lets the player through.
5-- Why?!?! ugh this is so frustrating

The reason is that when you use or you are in essence creating a new if statement. It is like saying:

1if "Name2" then

and that will always pass. Why? Because a string is truthy. It is not false or nil and seems true to the if statement because it exists. What you will need to do is:

1if player.Name == "Name" or player.Name == "Name2" then

and it works. There is a problem though. If you have a lot of names this will take forever to write and will look extremely ugly. I recommend having a table of names and looping through it. Here is the function I use:

01local admins = {"Name1", "Name2"}
02local function isAdmin(plr)
03 
04    for i,v in pairs(admins) do
05 
06        if v == plr.Name then
07 
08            return true
09 
10        end
11 
12    end
13 
14    return false
15 
16end
17if isAdmin(player) then
18-- this is a cleaner way to do it when you have a lot of names. Maybe not so worth it if you have two names. But three and beyond can benefit.

Hope this helps and have a great day scripting!

Ad
Log in to vote
-1
Answered by
Oficcer_F 207 Moderation Voter
6 years ago

As far as I am concerned, more then 1 "or" statement doesn't work... Correct me if I am wrong, but I am pretty sure. So line 49 and 55 are not working.

Answer this question