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

Help with Vip door?

Asked by
FiredDusk 1466 Moderation Voter
8 years ago

Teaching a 9 y/o how to script and I am having trouble atm :P Seems right to me. I am making a door where only certain people can go through it. I can go through it no matter what though. It does not kill me either.

Admins = {"Player", "PreyStar"}


script.Parent.Touched:connect(function(hit)
    if hit.Parent.Name == (Admins[1]) or (Admins[2]) or (Admins[3]) or (Admins[4]) then
        script.Parent.CanCollide = false
        wait(1)
        script.Parent.CanCollide = true
        print (hit.Parent.Name)
    end

    if hit.Parent.Name ~= (Admins[1]) or (Admins[2]) or (Admins[3]) or (Admins[4]) then
        hit.Parent:BreakJoints()
    end
end)

1 answer

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
8 years ago

or separates two distinct conditions.

if condition1 or condition2

condition1 and condition2 are in no way related!

if hit.Parent.Name == (Admins[1]) or (Admins[2])

The left side of or and the right side of or aren't connected in any way, shape, or form!

And equivalent way to write your code would be

if hit.Parent.Name == (Admins[1]) or (Admins[2]) == true

Since strings are considered to be true by Lua, the condition will always pass.

All you need to do is write your conditions separately.

if hit.Parent.Name == (Admins[1]) or hit.Parent.Name == (Admins[2])

Although admittedly using dictionaries would make your code shorter.

0
How could I write this in a dictionary form? Thanks for the help. FiredDusk 1466 — 8y
0
Look at the wiki link. It would be something like: admins = { ["Perci1"] = true } ... if admins[hit.Parent.Name] Perci1 4988 — 8y
0
The script is not working right. Even though my name is in the table, I am able to go through it but later kills me. FiredDusk 1466 — 8y
Ad

Answer this question