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

What's wrong with this? [SOLVED]

Asked by
JJ_B 250 Moderation Voter
8 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I wrote a doorbell script that opens a door when a certain person clicks it, but plays a sound otherwise. However, when anybody clicks it, the door just opens. Here is the script.

function doorbell(hit)
    local owner = hit.Parent.Name
    if owner == "Wizardel" or "Player" then
        script.Parent.Parent.RRD.Sound:Play()
    for i = 1, 60 do
        script.Parent.Parent.RRD.CFrame = script.Parent.Parent.RRD.CFrame*CFrame.new(0.2, 0, 0)
        wait()
    end
    wait(0.5)
    for i = 1, 60 do
        script.Parent.Parent.RRD.Sound:Play()       
        script.Parent.Parent.RRD.CFrame = script.Parent.Parent.RRD.CFrame*CFrame.new(-0.2, 0, 0)
    end
else
    script.Parent.Sound:play()
    end
end

script.Parent.ClickDetector.MouseClick:connect(doorbell)

Please help.

1 answer

Log in to vote
1
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
8 years ago

First, tab your code correctly!

This is a frequent mistake -- it's sort of an order-of-operations mistake. or is lower precedence than ==. That means your code is interpreted like this:

if (owner == "Wizardel") or "Player" then

thus, owner isn't actually being compared to "Player".

There's no such thing as one thing which is two things, so even if it was the other way

if owner == ("Wizardel" or "Player") then

that wouldn't make sense -- this would be the same thing as owner == "Wizardel".


If you want to use or, you have to be explicit about your comparisons:

if owner == "Wizardel" or owner == "Player" then

If you're adding a lot of names, you should use a list or a dictionary instead of making giant sets of or'd ==.

0
I did this, but now nobody can open the doors -_- JJ_B 250 — 8y
0
Did you try to debug at all? Did you `print(owner)` to see what it thinks the names are? Are they *exactly* how you spelled them? The testing player is usually `Player1`, *not* `Player` BlueTaslem 18071 — 8y
Ad

Answer this question