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

Why does my keycard door not work activating with every part?

So here's my script for my keycard door. I've stripped a few lines of code to try and find the problem.

script.Parent.OutsideButton.Reader.Touched:Connect(function(hit)
	if hit.Parent.Name == "Level 1 Card" or "Level 2 Card" then
		print("Activated.")
	end
end)

For some reason, it activates when any part touches it. Whether it be a player's body part or the wrong card. Can someone help me?

1 answer

✓ Accepted answer

you are using or statement wrong, it's hard to explain but here is how it shoud look:

script.Parent.OutsideButton.Reader.Touched:Connect(function(hit)
	local Card = hit.Parent.Name

	if Card == "Level 1 Card" or Card == "Level 2 Card" then
		print("Activated.")
	end
end)

Because in your case it will always open because it first checks if Card's name is Level 1 Card, if it's not, it will check if second argument is not nil because of or argument, string in your case is never nil so it will always pass, sorry for the "explanation", you just have to understand it.

2 comments

0

Thanks man!

0

No problem man!

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