How do I re-lock this door with a key? (Solved)

How do I make this script lock the door after I close it? I tried reading on conditional statements on the API developer article but I just don’t understand it :frowning:

Here’s the code and screenshot of the Explorer tab to get an idea. The door works fine mostly- but I can’t lock it after unlocking it by touching the door with the key tool.

Reference

door.Touched:connect(function(k)
	if k.Parent.Name == "Master Key" then
		clickDetector.MaxActivationDistance = 12
	end
end)

script.Parent.DoorClick.ClickDetector.MouseClick:Connect(Open)
2 Likes

Hey there, this might help:

put a boolvalue inside the door model name it “lock” or what ever you want but ill call it that for now.

Check if the tool is hitting the door.

script.Parent.Touched:Connect(function(Key)
if Key.Name == “GoldenKey” then
Lock.Value = true
else
Lock.Value = false
end

and to make the door open when clicking it after checking if it’s locked or not:

script.Parent.Touched(function(man)
if lock.value == false then
(the door opening script)

This is only to give you an idea, hope it helps

1 Like

I’ll try and mess with that a bit thank you

You may create a script when key touches door. The doors script just disables
if you touch again and locked value is true then its will enable the door script

Ok it’s been solved my headaches are gone now, didn’t check if it was locked or unlocked on the last block of code.