Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What's wrong with this? [SOLVED]

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

✓ Accepted answer

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

2 comments

0

I did this, but now nobody can open the doors -_-

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

This discussion is preserved as it was. New answers, comments, and votes are closed.