Having a strange problem here, I've created a script to open a door with a key.
function onTouched(hit) if hit.Parent.Name == "Room1" then script.Parent.CanCollide = false wait(1) script.Parent.CanCollide = true end end script.Parent.Touched:connect(onTouched)
This works just fine, but I also want it to be opened by a master key. When I try to add that to the script, the door constantly goes collidable and noncollidable on a loop, even when I'm not holding anything.
function onTouched(hit) if hit.Parent.Name == "Room1" or "MasterKey" then script.Parent.CanCollide = false wait(1) script.Parent.CanCollide = true end end script.Parent.Touched:connect(onTouched)
Please help?
The problem is in line 2, where you put in
if hit.Parent.Name == "Room1" or "MasterKey"
The problem is, you didn't specify the condition for "or", so the game checks whether the key's name is Room1, and then it checks if the string "MasterKey" exists, which it does by default.
You instead need to do
if hit.Parent.Name == "Room1" or hit.Parent.Name == "MasterKey"
This checks whether the key's name is Room1, or whether it's name is MasterKey.
Try this:
function onTouched(hit) local open = false if hit.Parent.Name == "Room1" or "MasterKey" then if open == false then open = true script.Parent.CanCollide = false wait(1) open = false script.Parent.CanCollide = true end end end script.Parent.Touched:connect(onTouched)