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)
This should work.
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 local angle = 90 Button.ClickDetector.MouseClick:Connect(function() if Debounce and not locked then Opened = not Opened Debounce = false for i = 0,2,.1 do Door:SetPrimaryPartCFrame(Door:GetPrimaryPartCFrame() * CFrame.Angles(0,math.rad((Opened and -(angle/20)) or (angle/20)),0)) wait() end Debounce = true end end) ClickDetector2.MouseClick:Connect(function() locked = not locked end)
local locked = mousedetector.MouseButton1down:connect(function(player) if player.Backpack:FindFirstChild("Key") then locked = false --open door else locked = true --door stays closed end end)
hopefully u get the concept my studio is crashing on me so ;(