So I have made an entire door script with CFrame that works just fine. But the important thing I need is a lock. I want to do it so that when I press a lock with a clickdetector the script detects that it's locked and you can no longer open the door until the lock is pressed again.
I have no idea how to do this, I tried a little but nothing works, please help me out!
Door script:
local Door = script.Parent.Parent
local Button = script.Parent
local Debounce = true
local Opened = false
local locked = false
local Lock = Door.Lockbutton
local ClickDetector2 = Lock.ClickDetector
Button.ClickDetector.MouseClick:connect(function()
if not Opened and Debounce then
Opened = true
Debounce = false
for i = 0,2,.1 do
Door:SetPrimaryPartCFrame(Door:GetPrimaryPartCFrame() * CFrame.Angles(0,math.rad(math.pi/-0.7),0))
wait()
end
Debounce = true
end
end)
wait(3)
Button.ClickDetector.MouseClick:connect(function()
if Opened and Debounce then
Opened = false
Debounce = false
for i = 0,2,.1 do
Door:SetPrimaryPartCFrame(Door:GetPrimaryPartCFrame() * CFrame.Angles(0,math.rad(math.pi/0.7),0))
wait()
end
Debounce = true
end
end)

1 comment
Dude thank you so much! It worked perfect! Thank alot!