Advertisement
2005zeus

Door module

Nov 23rd, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.47 KB | None | 0 0
  1. local module = {}
  2. ------------------------------------------------------------------------------------------
  3. -- Services
  4. local TweenService = game:GetService('TweenService')
  5. ------------------------------------------------------------------------------------------
  6. -- Vars
  7. local openModel = script.Parent.doorOpen
  8. local closeModel = script.Parent.doorClosed
  9. local currentModel = script.Parent.doorCurrent
  10.  
  11. local isOpen = true
  12. local duration = 6
  13.  
  14. local tweensTable = {
  15.     ["1"] = {},
  16.     ["2"] = {},
  17.     ["3"] = {},
  18.     ["4"] = {},
  19.     ["5"] = {}
  20. }
  21. ------------------------------------------------------------------------------------------
  22. -- Tween stuff
  23.  
  24. local function onInfo(duration)
  25.     -- When opening door
  26.     return TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.In)
  27. end
  28.  
  29. local function offInfo(duration)
  30.     -- When closing door
  31.     return TweenInfo.new(duration, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
  32. end
  33.  
  34. --------------------------------------
  35.  
  36. function module.Tween(on)
  37.     if isOpen == nil or on == isOpen then return end
  38.  
  39.     local boolStorer = nil
  40.  
  41.     isOpen = nil
  42.  
  43.     if on == true then
  44.         -- Will open
  45.         for i = 1, 6 do
  46.             if i > 2 then
  47.                 -- To top of vertical slider
  48.                 local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration * (i - 2) / 5), {CFrame = openModel.Model6.Frammmes.CFrame})
  49.                 local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration * (i - 2) / 5), {CFrame = openModel.Model6.Gladds.CFrame})      
  50.                 table.insert(tweensTable["1"], tween1)
  51.                 table.insert(tweensTable["1"], tween2)
  52.             end
  53.  
  54.             if i > 1 and i < 6 then
  55.                 -- Going to tilt
  56.                 local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration / 5), {CFrame = openModel.Model5.Frammmes.CFrame})
  57.                 local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration / 5), {CFrame = openModel.Model5.Gladds.CFrame})    
  58.                 table.insert(tweensTable[tostring(i - 1)], tween1)
  59.                 table.insert(tweensTable[tostring(i - 1)], tween2)
  60.             end
  61.  
  62.             if i < 5 then
  63.                 -- Going to Model4
  64.                 local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration / 5), {CFrame = openModel.Model4.Frammmes.CFrame})
  65.                 local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration / 5), {CFrame = openModel.Model4.Gladds.CFrame})    
  66.                 table.insert(tweensTable[tostring(i)], tween1)
  67.                 table.insert(tweensTable[tostring(i)], tween2)
  68.             end
  69.  
  70.             if i < 4 then
  71.                 -- Going to its Open positions
  72.                 local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration * (4 - i) / 5), {CFrame = openModel["Model".. tostring(i)].Frammmes.CFrame})
  73.                 local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration * (4 - i) / 5), {CFrame = openModel["Model".. tostring(i)].Gladds.CFrame})      
  74.                 table.insert(tweensTable[tostring(i + 1)], tween1)
  75.                 table.insert(tweensTable[tostring(i + 1)], tween2)
  76.             end
  77.  
  78.             boolStorer = true
  79.         end
  80.     elseif on == false then
  81.         -- Will clsoe
  82.         for i = 1, 6 do        
  83.             if i <= 3 then
  84.                 -- To Model4
  85.                 local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration * (4 - i) / 5), {CFrame = openModel.Model4.Frammmes.CFrame})
  86.                 local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration * (4 - i) / 5), {CFrame = openModel.Model4.Gladds.CFrame})
  87.                 table.insert(tweensTable["1"], tween1)
  88.                 table.insert(tweensTable["1"], tween2)
  89.             end
  90.  
  91.             if i < 5 then
  92.                 -- Tilt
  93.                 local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration / 5), {CFrame = openModel.Model5.Frammmes.CFrame})
  94.                 local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration / 5), {CFrame = openModel.Model5.Gladds.CFrame})    
  95.                 table.insert(tweensTable[tostring(5 - i)], tween1)
  96.                 table.insert(tweensTable[tostring(5 - i)], tween2)
  97.             end
  98.  
  99.             if i < 6 and i > 1 then
  100.                 -- Tilt back
  101.                 local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration / 5), {CFrame = openModel.Model6.Frammmes.CFrame})
  102.                 local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration / 5), {CFrame = openModel.Model6.Gladds.CFrame})    
  103.                 table.insert(tweensTable[tostring(6 - i)], tween1)
  104.                 table.insert(tweensTable[tostring(6 - i)], tween2)
  105.             end
  106.  
  107.             if i <= 6 and i > 2 then
  108.                 -- Go to its respective closed positions
  109.                 local tween1 = TweenService:Create(currentModel["Model".. tostring(i)].Frammmes, onInfo(duration * (i - 2) / 5), {CFrame = closeModel["Model".. tostring(i)].Frammmes.CFrame})
  110.                 local tween2 = TweenService:Create(currentModel["Model".. tostring(i)].Gladds, onInfo(duration * (i - 2) / 5), {CFrame = closeModel["Model".. tostring(i)].Gladds.CFrame})     
  111.                 table.insert(tweensTable[tostring(7 - i)], tween1)
  112.                 table.insert(tweensTable[tostring(7 - i)], tween2)
  113.             end        
  114.         end
  115.  
  116.         boolStorer = false
  117.     end
  118.  
  119.     for i = 1, 5 do
  120.         for _, tweenThing in pairs(tweensTable[tostring(i)])do
  121.             tweenThing:Play()
  122.         end
  123.         wait(duration / 5)
  124.     end
  125.  
  126.     isOpen = boolStorer
  127.  
  128.     -- Emptying to prevent data leaks
  129.     tweensTable = {
  130.         ["1"] = {},
  131.         ["2"] = {},
  132.         ["3"] = {},
  133.         ["4"] = {},
  134.         ["5"] = {}
  135.     }
  136. end
  137.  
  138. ------------------------------------------------------------------------------------------
  139. return module
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement