Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- // Services
- local TweenService = game:GetService("TweenService")
- -- // Variables
- local State = script.Parent:WaitForChild("State")
- local Busy = script.Parent:WaitForChild("Busy")
- local Door = script.Parent:WaitForChild("Door")
- local Ladder = script.Parent:WaitForChild("Ladder")
- local DoorObjects = {
- Knobs = Door:WaitForChild("Knobs"),
- LockModel = Door:WaitForChild("LockModel"),
- Rope = Door:WaitForChild("Rope"),
- Ladder1 = Ladder,
- Ladder2 = Ladder:WaitForChild("Second"),
- Ladder3 = Ladder.Second:WaitForChild("Third")
- }
- local OriginalCFrames = {
- Knobs = DoorObjects.Knobs.PrimaryPart.CFrame,
- LockModel = DoorObjects.LockModel.PrimaryPart.CFrame,
- Rope = DoorObjects.Rope.PrimaryPart.CFrame,
- Ladder1 = DoorObjects.Ladder1.PrimaryPart.CFrame,
- Ladder2 = DoorObjects.Ladder2.PrimaryPart.CFrame,
- Ladder3 = DoorObjects.Ladder3.PrimaryPart.CFrame
- }
- function TweenModel(Obj, Info, Pos, Wait)
- local OldCFrame = Obj:FindFirstChild(Obj.Name)
- if OldCFrame and OldCFrame:IsA("CFrameValue") then OldCFrame:Destroy() end
- local CFrameValue = Instance.new("CFrameValue")
- CFrameValue.Name = Obj.Name
- CFrameValue.Parent = Obj
- CFrameValue.Value = Obj:GetPrimaryPartCFrame()
- CFrameValue:GetPropertyChangedSignal("Value"):Connect(function() Obj:SetPrimaryPartCFrame(CFrameValue.Value) end)
- local TweenInf = TweenInfo.new(Info.Time,Info.Style,Info.Direction,Info.Repeat or 0,Info.Reverse or false)
- local Tween = TweenService:Create(CFrameValue, TweenInf, {Value = Pos})
- Tween:Play()
- Tween.Completed:Connect(function()
- if Wait then
- Wait()
- end
- if CFrameValue ~= nil then
- CFrameValue:Destroy()
- end
- end)
- end
- function OpenAtticDoor()
- local Info = {Time = 0.6, Style = Enum.EasingStyle.Back, Direction = Enum.EasingDirection.Out}
- local Pos = OriginalCFrames.Knobs * CFrame.Angles(math.rad(45), 0, 0)
- TweenModel(DoorObjects.Knobs, Info, Pos)
- local Info = {Time = 0.6, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out}
- local Pos = OriginalCFrames.Rope * CFrame.new(0, 0, -5)
- TweenModel(DoorObjects.Rope, Info, Pos)
- wait(0.6)
- local Info = {Time = 0.7, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out}
- local Pos = Door.PrimaryPart.CFrame * CFrame.Angles(math.rad(-90), 0, 0)
- TweenModel(Door, Info, Pos)
- wait(.5)
- local Info = {Time = 0.4, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out}
- local Pos = script.Parent.Ladder.Ladder1.CFrame * CFrame.Angles(math.rad(-90), 0, 0)
- TweenModel(DoorObjects.Ladder1, Info, Pos)
- wait(.5)
- local Info = {Time = 0.4, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out}
- local Pos = script.Parent.Ladder.Second.Ladder2.CFrame * CFrame.Angles(math.rad(190), 0, 0)
- TweenModel(DoorObjects.Ladder2, Info, Pos)
- wait(.5)
- local Info = {Time = 0.4, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out}
- local Pos = script.Parent.Ladder.Second.Third.Ladder3.CFrame * CFrame.Angles(math.rad(-190), 0, 0)
- TweenModel(DoorObjects.Ladder3, Info, Pos)
- end
- function CloseAtticDoor()
- local Info = {Time = 0.7, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out}
- local Pos = Door.PrimaryPart.CFrame
- TweenModel(Door, Info, Pos)
- wait(0.7)
- local Info = {Time = 0.6, Style = Enum.EasingStyle.Quad, Direction = Enum.EasingDirection.Out}
- local Pos = OriginalCFrames.Knobs
- TweenModel(DoorObjects.Knobs, Info, Pos)
- local Info = {Time = 0.6, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out}
- local Pos = OriginalCFrames.Rope
- TweenModel(DoorObjects.Rope, Info, Pos)
- wait(.5)
- local Info = {Time = 0.4, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out}
- local Pos = OriginalCFrames.Ladder1
- TweenModel(DoorObjects.Ladder1, Info, Pos)
- wait(.5)
- local Info = {Time = 0.4, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out}
- local Pos = OriginalCFrames.Ladder2
- TweenModel(DoorObjects.Ladder2, Info, Pos)
- wait(.5)
- local Info = {Time = 0.4, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out}
- local Pos = OriginalCFrames.Ladder3
- TweenModel(DoorObjects.Ladder3, Info, Pos)
- end
- function Locked()
- local Info = {Time = 0.1, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out, Repeat = 3, Reverse = true}
- local Pos = OriginalCFrames.Knobs * CFrame.Angles(math.rad(35), 0, 0)
- TweenModel(DoorObjects.Knobs, Info, Pos)
- end
- function CrankRotate1()
- local Info = {Time = 0.4, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out}
- local Pos = OriginalCFrames.LockModel * CFrame.Angles(math.rad(90), 0, 0)
- TweenModel(DoorObjects.LockModel, Info, Pos)
- end
- function CrankRotate2()
- local Info = {Time = 0.4, Style = Enum.EasingStyle.Sine, Direction = Enum.EasingDirection.Out}
- local Pos = OriginalCFrames.LockModel
- TweenModel(DoorObjects.LockModel, Info, Pos)
- end
- for i, v in pairs(Door:GetDescendants()) do
- if v:IsA("ClickDetector") and v.Name == "OpenCloseLockableDoor" then
- v.MouseClick:Connect(function(Player)
- if Busy.Value then return end
- if State.Value ~= "Locked" then
- if State.Value ~= "Open" then
- if State.Value == "Close" then
- State.Value = "Open"
- Busy.Value = true
- print("opening door function, name: " .. script.Name .. ".lua")
- coroutine.wrap(OpenAtticDoor)()
- wait(0.8)
- Busy.Value = false
- end
- end
- elseif State.Value ~= "Close" then
- if State.Value == "Open" then
- Busy.Value = true
- State.Value = "Close"
- print("closing door function, name: " .. script.Name .. ".lua")
- coroutine.wrap(CloseAtticDoor)()
- wait(1.6)
- Busy.Value = false
- end
- elseif State.Value ~= "Open" then
- if State.Value == "Locked" then
- Busy.Value = true
- coroutine.wrap(Locked)()
- print("locked door function, name: " .. script.Name .. ".lua")
- wait(0.8)
- Busy.Value = false
- end
- end
- end)
- end
- end
- for i, v in pairs(Door:GetDescendants()) do
- if v:IsA("ClickDetector") and v.Name == "ToggleLock" then
- v.MouseClick:Connect(function(Player)
- if Busy.Value then return end
- if State.Value ~= "Locked" then
- if State.Value ~= "Open" then
- if State.Value == "Close" then
- State.Value = "Locked"
- CrankRotate1()
- Busy.Value = true
- wait(0.45)
- Busy.Value = false
- end
- end
- elseif State.Value == "Locked" then
- if State.Value ~= "Open" then
- State.Value = "Close"
- CrankRotate2()
- Busy.Value = true
- wait(0.45)
- Busy.Value = false
- end
- end
- end)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement