Last active
March 15, 2021 11:39
-
-
Save RealSGII2/e30c7a0f9419a4c031f7daf3a4191296 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| local CS = game:GetService("CollectionService"); | |
| local TS = game:GetService("TweenService") | |
| local OPEN_SOUND = "rbxassetid://3272350111"; | |
| local CLOSE_SOUND = "rbxassetid://3272350111"; | |
| local LabDoor = {}; | |
| LabDoor.__index = LabDoor; | |
| LabDoor.TAGNAME = "LabDoor"; | |
| LabDoor.MovementTime = 0.7; | |
| LabDoor.Cooldown = 4; | |
| function LabDoor.new(DoorObject) | |
| local self = {}; | |
| setmetatable(self, LabDoor); | |
| self.Object = DoorObject; | |
| self.IsDeleted = false; | |
| self.IsIdle = true; | |
| self.IsOpen = false; | |
| self.Objects = {}; | |
| self.Objects.Detector = DoorObject["Detector"]; | |
| self.Objects.Door1 = DoorObject["Door1"]; | |
| self.Objects.Door2 = DoorObject["Door2"]; | |
| self.Objects.Sounds = {}; | |
| self.Objects.Sounds.Open = DoorObject["Frame"]["Open"]; | |
| self.Objects.Sounds.Close = DoorObject["Frame"]["Close"]; | |
| self.Objects.Sounds.Open.SoundID = OPEN_SOUND; | |
| self.Objects.Sounds.Close.SoundID = CLOSE_SOUND; | |
| self.TweenInformation = TweenInfo.new( | |
| self.MovementTime, | |
| Enum.EasingStyle.Quad, | |
| Enum.EasingDirection.InOut, | |
| 0, | |
| false, | |
| 0 | |
| ); | |
| self.OpenDoor1 = TS:Create( | |
| self.Object.Door1, | |
| self.TweenInformation, | |
| { CFrame = self.Object.Door1.CFrame * CFrame.new(-4, 0, 0) } | |
| ); | |
| self.OpenDoor2 = TS:Create( | |
| self.Object.Door2, | |
| self.TweenInformation, | |
| { CFrame = self.Object.Door2.CFrame * CFrame.new(-4, 0, 0) } | |
| ); | |
| self.CloseDoor1 = TS:Create( | |
| self.Object.Door1, | |
| self.TweenInformation, | |
| { CFrame = self.Object.Door1.CFrame * CFrame.new(0, 0, 0) } | |
| ); | |
| self.CloseDoor2 = TS:Create( | |
| self.Object.Door2, | |
| self.TweenInformation, | |
| { CFrame = self.Object.Door2.CFrame * CFrame.new(0, 0, 0) } | |
| ); | |
| self.LookForUsers = spawn(function() | |
| while (wait()) do | |
| --if (self.IsDeleted == false) then | |
| for _, User in pairs(game.Players:GetPlayers()) do | |
| if (User.Character and User.Character:FindFirstChild("Torso")) then | |
| if ((self.Objects.Detector.Position - User.Character.Torso.Position).Magnitude <= 14) then | |
| self:OpenSequence(); | |
| end | |
| end | |
| end | |
| --end | |
| end | |
| end) | |
| end | |
| function LabDoor:Open() | |
| self.OpenDoor1:Play(); | |
| self.OpenDoor2:Play(); | |
| self.Objects.Sounds.Open:Play(); | |
| self.IsOpen = true; | |
| end | |
| function LabDoor:Close() | |
| self.CloseDoor1:Play(); | |
| self.CloseDoor2:Play(); | |
| self.Objects.Sounds.Close:Play(); | |
| self.IsOpen = false; | |
| end | |
| function LabDoor:OpenSequence() | |
| if (self.IsIdle == false) then return end; | |
| self.IsIdle = false; | |
| self:Open(); | |
| wait(self.MovementTime + self.Cooldown); | |
| self:Close(); | |
| wait(self.MovementTime); | |
| self.IsIdle = true; | |
| end | |
| function LabDoor:Remove() | |
| self.IsDeleted = true; | |
| end | |
| local Doors = {}; | |
| local DoorAddedEvent = CS:GetInstanceAddedSignal(LabDoor.TAGNAME); | |
| local DoorRemovedEvent = CS:GetInstanceRemovedSignal(LabDoor.TAGNAME); | |
| local function DoorAdded(DoorObject) | |
| if (DoorObject:IsA("Model") and DoorObject:FindFirstChild("Detector")) then | |
| Doors[DoorObject] = LabDoor.new(DoorObject); | |
| end | |
| end | |
| local function DoorRemoved(DoorObject) | |
| if Doors[DoorObject] then | |
| Doors[DoorObject]:Remove() | |
| Doors[DoorObject] = nil | |
| end | |
| end | |
| for _, _Instance in pairs(CS:GetTagged(LabDoor.TAGNAME)) do | |
| DoorAdded(_Instance) | |
| end | |
| DoorAddedEvent:Connect(DoorAdded) | |
| DoorRemovedEvent:Connect(DoorRemoved) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment