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.
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 ==
.