I've been on this script for I kid you not 8 hours plus trying to find help online but nobody has given me any helpful tips so I come here asking for aid, somebody said to use a bool value so I did but the lock and unlock code at line - 39 only unlocks the door, but can't be relocked again.
-- Needs to be locked and unlockable. So far it can only be Unlocked.
local Hinge = script.Parent.PrimaryPart
local opened = false
local door = script.Parent.DoorClick
local clickDetector = door.ClickDetector
local doorunlocksound = script.Parent.DoorClick.DoorUnlock
local doorlocksound = script.Parent.DoorClick.DoorLocked
local doorlock = script.Parent.Lock
function Open()
if opened == false then
opened = true
for i = 1, 10 do
script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(9), 0))
for _,v in pairs(script.Parent.Parent:GetDescendants()) do
if v:IsA("BasePart") then
v.CanCollide = false
end
end
wait()
end
else
opened = false
for i = 1, 10 do
script.Parent:SetPrimaryPartCFrame(Hinge.CFrame*CFrame.Angles(0, math.rad(-9), 0))
wait()
for _,v in pairs(script.Parent.Parent:GetDescendants()) do
if v:IsA("BasePart") then
v.CanCollide = true
end
end
end
end
end
script.Parent.DoorClick.ClickDetector.MouseClick:Connect(Open)
-- the issue vvv
door.Touched:Connect(function(k)
if k.Parent.Name == "Master Key" then
doorlocksound:Play()
doorlock.Value = true
clickDetector.MaxActivationDistance = 0
else
doorunlocksound:Play()
doorlock.Value = false
clickDetector.MaxActivationDistance = 12
end
end)

1 comment
THANK YOU SO MUCH! You saved me probably another 24 hours of struggle over a door. I tried reading the developer API on statements and conditions but it's really hard for me to understand it!